package com;
public class us {
private int userid;
private String username;
private String userpassword;
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpassword() {
return userpassword;
}
public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}
}
<form action="insert.jsp">
账号: <input type="text" name="userid"><br>
姓名:<input type="text" name="username"><br>
密码:<input type="text" name="userpassword"><br>
<input type="submit" name="usersex" value="注册"><br>
</form>
<jsp:useBean id="us" class="com.us" scope="request"></jsp:useBean>
<jsp:setProperty name="us" property="*"></jsp:setProperty>
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://127.0.0.1:3306/submit?user=root&password=root";
Connection connection= DriverManager.getConnection(url);
String sql="insert into user(userid,username,userpassword) values("+us.getUserid()+",'"+us.getUsername()+"','"+us.getUserpassword()+"')";
Statement stmt=connection.createStatement();
int count=stmt.executeUpdate(sql);
if (count==0)
{
out.print("失败");
}
else
{
out.print("成功");
}