我的jsp代码为什么不能将数据插入到数据库中 sql1可以正确查询 但是sql2就不能正确执行
Stringsql1="select*fromuserwhereusername='"+username+"'";Stringsql2="insertintouser(u...
String sql1="select * from user where username= '" + username+ "' ";
String sql2="insert into user (username,u_password,u_name,u_age,u_sex,u_brithday,u_hometown,u_admission_y,u_identity,u_phone,u_qq,u_email,u_department,u_profession,u_class,u_hobbies,u_futurework,u_remark,u_description) values('"+username+"','"+u_password+"',"+u_name+",parseInt("+u_age+"),'"+u_sex+"','"+u_brithday+"','"+u_hometown+"','"+u_admission_y+"','"+u_identity+"','"+u_phone+"','"+u_qq+"','"+u_email+"','"+u_department+"','"+u_profession+"','"+u_class+"','"+u_hobbies+"','"+u_futurework+"','"+u_remark+"','"+u_description+"')";
try{
Connection conn=DatabaseUtil.getConnection();
Statement stmt=conn.createStatement();
if(username!="" && u_password!="" && u_name!=""&& request.getParameter("u_age")!="" && u_brithday!="" && u_admission_y!=null && u_hometown!="" && u_department!="" && u_profession!="" && u_class!="" ){
ResultSet rs=stmt.executeQuery(sql1);
if(rs.next()) {
out.println("<br/><h2><font color='red'>该用户名已经存在!请重新填写注册信息!3秒后返回注册页面!</font></h2>");
response.setHeader("Refresh","3;URL=register.jsp");
}else{
stmt.executeUpdate(sql2);
out.println("<br/><h2><font color='red'>亲爱的会员,您已经注册成功!3秒后返回登录页面,请您重新登录!</font></h2>");
response.setHeader("Refresh","3;URL=login.jsp");
}
}else{
out.println("<br/><h2><font color='red'>您填写的注册信息有误!请按照要求重新填写注册信息!3秒后返回注册页面!</font></h2>");
response.setHeader("Refresh","3;URL=register.jsp");
}
DatabaseUtil.close(conn);
}catch (Exception e)
{
e.printStackTrace();
} 展开
String sql2="insert into user (username,u_password,u_name,u_age,u_sex,u_brithday,u_hometown,u_admission_y,u_identity,u_phone,u_qq,u_email,u_department,u_profession,u_class,u_hobbies,u_futurework,u_remark,u_description) values('"+username+"','"+u_password+"',"+u_name+",parseInt("+u_age+"),'"+u_sex+"','"+u_brithday+"','"+u_hometown+"','"+u_admission_y+"','"+u_identity+"','"+u_phone+"','"+u_qq+"','"+u_email+"','"+u_department+"','"+u_profession+"','"+u_class+"','"+u_hobbies+"','"+u_futurework+"','"+u_remark+"','"+u_description+"')";
try{
Connection conn=DatabaseUtil.getConnection();
Statement stmt=conn.createStatement();
if(username!="" && u_password!="" && u_name!=""&& request.getParameter("u_age")!="" && u_brithday!="" && u_admission_y!=null && u_hometown!="" && u_department!="" && u_profession!="" && u_class!="" ){
ResultSet rs=stmt.executeQuery(sql1);
if(rs.next()) {
out.println("<br/><h2><font color='red'>该用户名已经存在!请重新填写注册信息!3秒后返回注册页面!</font></h2>");
response.setHeader("Refresh","3;URL=register.jsp");
}else{
stmt.executeUpdate(sql2);
out.println("<br/><h2><font color='red'>亲爱的会员,您已经注册成功!3秒后返回登录页面,请您重新登录!</font></h2>");
response.setHeader("Refresh","3;URL=login.jsp");
}
}else{
out.println("<br/><h2><font color='red'>您填写的注册信息有误!请按照要求重新填写注册信息!3秒后返回注册页面!</font></h2>");
response.setHeader("Refresh","3;URL=register.jsp");
}
DatabaseUtil.close(conn);
}catch (Exception e)
{
e.printStackTrace();
} 展开
2个回答
展开全部
报什么异常呀?,肯定是sql2语句有问题
追问
因为我这是个检验的页面他就一直停留在这个页面 也不报错 但是应该是sql语句的问题可是不知道为什么就是不对
追答
你在try上面加个打印试试:
System.out.println(sql2);
然后贴出那个打印结果分析一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询