5

后台 注册页面数据插入的实现,正常运行不报错但数据库中插不进数据

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="com.two.dao.*"%>
<%@ page import="java.util.*"%>
<%
request.setCharacterEncoding("UTF-8");
String action = request.getParameter("action");
if(action != null && action.trim().equals("register")) {
String register_name = request.getParameter("register_name");
String register_password = request.getParameter("register_password");
String register_password2 = request.getParameter("register_password2");
String register_phone = request.getParameter("register_phone");
String register_address = request.getParameter("register_address");
String register_email = request.getParameter("register_email");
RegisterDao u = new RegisterDao();

u.setRegister_name(register_name);
u.setRegister_password(register_password);
u.setRegister_password2(register_password2);
u.setRegister_phone(register_phone);
u.setRegister_address(register_address);
u.setRegister_email(register_email);

out.println("注册成功!恭喜!");
return;

}
%>public class JDBC {
private static final String URL = "jdbc:mysql://localhost:3306/myceshi";
private static final String USER = "root";
private static final String PASSWORD = "root";

static {
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        System.out.println("加载Mysql数据库驱动失败!");
    }
}   public void setRegister_email(String register_email) {
    this.register_email = register_email;
}
public void save() {
    Connection conn = DB.getConn();
    String sql = "insert into register values (null,?, ?, ?, ?, ?, ?)";
    PreparedStatement pstmt = DB.prepare(conn, sql);
    try {
        pstmt.setString(1, register_name );
        pstmt.setString(2, register_password);
        pstmt.setString(3, register_password2);
        pstmt.setString(4, register_phone);
        pstmt.setString(5, register_address);
        pstmt.setString(6,  register_email);
        pstmt.executeUpdate();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DB.close(pstmt);
        DB.close(conn);
    }

}



}![图片说明](https://img-ask.csdn.net/upload/201705/10/1494408179_305481.png)

查看全部
WDbairen
WDbairen
2017/05/10 09:30
  • java
  • 注册
  • 数据库
  • eclipse
  • 点赞
  • 收藏
  • 回答
    私信

2个回复