插入数据库出错,新手求教
错误是:
The server encountered an internal error () that prevented it from fulfilling this request.exception
java.lang.NullPointerException cn.wy.CtrlServlet.Reg.processRequest(Reg.java:63)
cn.wy.CtrlServlet.Reg.doPost(Reg.java:86)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
源码:
DBConnection dbc=null;
String userEmail;
String userName;
String userPwd;
//int userSex;
//Date userbirthday = null;
//String userSchool;
response.setContentType("text/html;charset=UTF-8");
out = response.getWriter();
try{ dbc = new DBConnection();
PreparedStatement ps = null;
userEmail = request.getParameter("userEmail");
userName = request.getParameter("userName");
userPwd = request.getParameter("userPwd");
System.out.print(userEmail);
System.out.print(userName);
System.out.print(userPwd);
//userSex = Integer.parseInt(request.getParameter("userSex"));
//userSchool = request.getParameter("userSchool");
if (userName != null && userPwd != null && userEmail != null)
{
ps = dbc.getCon().prepareStatement("insert into ceshi (userEmail,userName,userPwd)" +" values(?,?,?)");
ps.setString(1, userEmail);
ps.setString(2, userName);
ps.setString(3, userPwd);
// //ps.setDate(5, userbirthday);
//ps.setInt(4, userSex);
ps = dbc.getCon().prepareStatement("insert into ceshi values(userEmail,userName,userPwd)");
ps.execute();
System.out.print("新用户注册:" + request.getParameter("userName") + " ");
out.print("<script>alert('恭喜您:注册成功!现已经登录到网站!');history.go(-1)</script>");
}
if (dbc != null)
dbc.dbClose();
}
catch(
SQLException ex)
{ out.print("<script>alert('注册失败!数据库连接错误!');history.go(-1)</script>");
ex.printStackTrace();
if (dbc != null)
dbc.dbClose(); }
}
------解决方案--------------------施主...调试下吧...明显告诉你是
NullPointerException ...
------解决方案-------------------- 或者重启去吧
------解决方案--------------------空指针异常cn.wy.CtrlServlet.Reg.processRequest(Reg.java:63)63行,分析下吧,别人帮不了你
------解决方案--------------------首先,看你要写的几个值打印出来都不是null
其次,看看你数据库字段设的属性是什么,是否长度不够
------解决方案--------------------看看这行附近的变量在使用前是不是忘记赋值了。
cn.wy.CtrlServlet.Reg.processRequest(Reg.java:63)
空指针异常 基本