PreparedStatement执行prep.executeUpdate();抛异常了。为啥

我写的方法
public void save(String userName, String passWord, String email,
String pType)
{
JobDataJtds j = new JobDataJtds();
System.out.println(j);
Connection conn = j.getConnection();
System.out.println(conn);
try
{

PreparedStatement prep = conn
.prepareStatement("insert into userinfo(Username,Pwd,Email,Ptype) values(?,?,?,?)");

prep.setString(1, userName);
prep.setString(2, passWord);
prep.setString(3, email);
prep.setString(4, pType);
prep.executeUpdate();
prep.close();

} catch (SQLException e)
{
// TODO Auto-generated catch block
System.out.println("用户注册时出错=====" + e.getMessage());
}

j.getCloseConnection(conn);

}
我写的action
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
request.setCharacterEncoding("gbk");

UserinfoDao userinfoDao = new UserinfoDao();
System.out.println(userinfoDao);

String userName = request.getParameter("userName");
System.out.println(userName);
String passWord = request.getParameter("pwd");
System.out.println(passWord);
String email = request.getParameter("email");
System.out.println(email);
String pType = request.getParameter("ptype");
System.out.println(pType);
if (userinfoDao.check(userName) == true)
{
userinfoDao.save(userName, passWord, email, pType);
return mapping.findForward("succ");

} else
{
request.setAttribute("msg", "用户名已被占用");
return mapping.findForward("err");
}

}

你可能感兴趣的:(J#)