从jsp页面往SQL2005插入数据报错
错误是: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(); }
}
[解决办法]
建议单步调试你的程序 上面的显示错误应该不是数据库报错
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html