<body>
<%
String driverName="com.mysql.jdbc.Driver";
String userName="root";//用户名
String userPwd="123456";//用户密码
String dbName="user";//调用数据库
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driverName);
Connection conn=DriverManager.getConnection(url);
String sql="Insert use_a(uname,upassword)values(?,?)";//向数据库里面的表格添加信息。
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,"***");
pstmt.setString(2, "liu123456");
int n=pstmt.executeUpdate();
if(n==1)
{%>恭喜你注册成功!请点击返回按钮进入登陆界面。<input type="button" value="返回" onclick="window.location.href='login.jsp';"/><br><%}
else{%>注册失败!请重新注册!<input type="button" value="重新注册" onclick="window.location.href='zhuce.jsp';"/><br><%}
if(pstmt!=null){pstmt.close();}
if(conn!=null){conn.close();}
%>
</body>
通过jsp向mysql数据库里面加入用户名与密码的主要代码。。。。
最新推荐文章于 2023-10-22 20:24:15 发布
