1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| <%-- Created by IntelliJ IDEA. User: DELL Date: 2022/10/12 Time: 14:55 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %> <%@ page import="com.mysql.jdbc.Driver" %> <% request.setCharacterEncoding("UTF-8"); String bookname = request.getParameter("bookname"); String author = request.getParameter("author"); String press = request.getParameter("press"); String price = request.getParameter("price"); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","wangzhe2412"); String sql = "insert into bookinfo values(null,?,?,?,?)"; PreparedStatement pstmt =con.prepareStatement(sql); pstmt.setString(1,bookname); pstmt.setString(2,author); pstmt.setString(3,press); pstmt.setFloat(4,Float.parseFloat(price)); int result = pstmt.executeUpdate(); String msg = "添加失败,单击确定跳转到图书列表页"; if(result == 1){ msg = "添加成功,单击确定跳转到图书列表页"; } pstmt.close(); con.close(); %> <script> window.alert('<%= msg%>'); </script> <% response.setHeader("Refresh","1,url =./index.jsp"); %> <html> <head> <title>Title</title> </head> <body>
</body> </html>
|