|
@@ -1,80 +0,0 @@
|
|
|
-<%@ page language="java" contentType="text/html; charset=utf-8"%>
|
|
|
-<%@ page import="java.sql.*"%>
|
|
|
-<% request.setCharacterEncoding("utf-8") ;%>
|
|
|
-<%-- <%@ page import="com.mchange.v2.c3p0.ComboPooledDataSource" %> --%>
|
|
|
-<!DOCTYPE html>
|
|
|
-<html>
|
|
|
-<head>
|
|
|
-<meta charset="utf-8">
|
|
|
-<title>Insert title here</title>
|
|
|
-</head>
|
|
|
-<body>
|
|
|
- <%
|
|
|
- Class.forName("com.mysql.cj.jdbc.Driver");
|
|
|
- String url = "jdbc:mysql://localhost:3306/bookstores?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8"; //指向数据库table1
|
|
|
- String username = "root";
|
|
|
- String password = "2722612";
|
|
|
- Connection conn = null;
|
|
|
- conn = DriverManager.getConnection(url, username, password);
|
|
|
-
|
|
|
- if(conn != null){
|
|
|
- /* Statement stmt = conn.createStatement(); */
|
|
|
- String id=request.getParameter("ID");
|
|
|
- String name=request.getParameter("name");
|
|
|
- String age=request.getParameter("age");
|
|
|
- String sex=request.getParameter("sex");
|
|
|
-
|
|
|
- if(id.equals("")|name.equals("")|sex.equals("")){
|
|
|
- response.sendRedirect("Student.jsp");
|
|
|
- }else{
|
|
|
- out.println("数据源配置正确");
|
|
|
- out.println("<br />");
|
|
|
- out.println("=====================================================");
|
|
|
- out.println("<br />");
|
|
|
-
|
|
|
- Statement stmt = null;
|
|
|
- ResultSet rs = null;
|
|
|
- PreparedStatement pstmt = null;
|
|
|
- //String sql = "insert into title(id,name,sex) values('"+id+"','"+name+"','"+sex+"')";
|
|
|
- //String sql = "INSERT INTO title (id,name,age,gender) "
|
|
|
- //+"VALUES (880,'菜菜',12,'女')";
|
|
|
-
|
|
|
- String sql = "INSERT INTO SZIIT (ID,name,age,sex) "
|
|
|
- +"VALUES (?,?,?,?)";
|
|
|
-
|
|
|
-
|
|
|
- stmt = conn.createStatement();
|
|
|
- pstmt = conn.prepareStatement(sql);
|
|
|
- pstmt.setString(1,id);
|
|
|
- pstmt.setString(2,name);
|
|
|
- pstmt.setString(3,age);
|
|
|
- pstmt.setString(4,sex);
|
|
|
- pstmt.executeUpdate();
|
|
|
-
|
|
|
- /* stmt.executeUpdate(sql); */
|
|
|
- out.print("成功添加好友:");
|
|
|
- out.print("<br>");
|
|
|
- out.print("------------------------------------------------");
|
|
|
- out.println("<br>");
|
|
|
- String sqll ="select * from student";
|
|
|
- rs = stmt.executeQuery(sqll);
|
|
|
-
|
|
|
- /* name=new String(name.getBytes("utf-8"));
|
|
|
- out.print(name); */
|
|
|
- // rs.next();
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
- }
|
|
|
- else{
|
|
|
- out.print("连接失败!");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- %>
|
|
|
- <br><br>
|
|
|
- <!-- <a href="Student.jsp"> 返回管理首页</a> -->
|
|
|
-
|
|
|
-</body>
|
|
|
-</html>
|