javawebb

 <%@ page language="java" import="java.sql.*" import="java.util.*" pageEncoding="UTF-8"%>
<html>
  <head>
    <title>Insert</title>
  </head>
  <body>
    <%
   String driverName="com.mysql.jdbc.Driver";
   String dbName="MyLogin";
   String userName="root";
   String userPwd="5201314";
   String url1="jdbc:mysql://localhost:3306/MyLogin";
   String url2="?user=root&password=5201314";
   String url3="&useUnicode=true&characterEncoding=UTF-8";
   String url=url1+url2+url3;
   Class.forName(driverName);
   Connection conn=DriverManager.getConnection(url);
   String ss="Insert into checklog(id,password)values(?,?)";
   PreparedStatement pstmt=conn.prepareStatement(ss);
   request.setCharacterEncoding("UTF-8");
   int id=Integer.parseInt(request.getParameter("ZName"));
   int password=Integer.parseInt(request.getParameter("ZPassword"));
   pstmt.setInt(1,id);
   pstmt.setInt(2,password);
   int n=pstmt.executeUpdate();
   if(n==1){%>注册成功!<br><br><a href="http://localhost:8080/JavaWork/Login.jsp">返回登录界面!!</a><%}else{%>数据插入失败!<br><%}
   if(pstmt!=null){pstmt.close();}
   if(conn!=null){conn.close();} %>
  </body>
</html>
 

posted on 2017-12-03 22:59  哈哈呵  阅读(92)  评论(0)    收藏  举报

导航