|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
<%@ page import="java.sql.*" %>
<%
// 获取表单中的商品信息
String name = request.getParameter("name");
double price = Double.parseDouble(request.getParameter("price"));
int quantity = Integer.parseInt(request.getParameter("quantity"));
// 将商品信息保存到数据库中
String url = "jdbc:mysql://localhost:3306/111";
String user = "root";
String password = "123456";
Connection conn = DriverManager.getConnection(url, user, password);
String sql = "INSERT INTO products (name, price, quantity) VALUES (?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
stmt.setDouble(2, price);
stmt.setInt(3, quantity);
stmt.executeUpdate();
stmt.close();
conn.close();
%>
<!DOCTYPE html>
<html>
<head>
<title>保存成功</title>
</head>
<body>
<h1>保存成功</h1>
<p>商品名称: <%= name %></p>
<p>单价: <%= price %></p>
<p>数量: <%= quantity %></p>
</body>
</html> |
|