ResultSet RS_result=connDbBean.executeQuery("select * from yonghuzhuce where yonghuming='"+yonghuming+"'"); if(RS_result.next()) { out.print("<script>alert('该用户名已经存在,请换其他名称的用户名!');window.history.go(-1);</script>"); } else{ String addtimes = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); String sql="insert into yonghuzhuce(yonghuming,mima,xingming,xingbie,chushengnianyue,QQ,youxiang,dianhua,shenfenzheng,touxiang,dizhi,beizhu,addtime,issh) values('"+yonghuming+"','"+mima+"','"+xingming+"','"+xingbie+"','"+chushengnianyue+"','"+QQ+"','"+youxiang+"','"+dianhua+"','"+shenfenzheng+"','"+touxiang+"','"+dizhi+"','"+beizhu+"','"+addtimes+"','y') "; connDbBean.executeUpdate(sql); out.print("<script>alert('注册成功!');location.href='index.jsp';</script>"); } RS_result.close();请给这段代码加上注释
时间: 2024-04-05 08:35:20 浏览: 81
// 根据用户名查询是否已存在
ResultSet RS_result = connDbBean.executeQuery("select * from yonghuzhuce where yonghuming='" + yonghuming + "'");
if(RS_result.next()) {
// 如果查询结果不为空,则输出错误提示信息,并返回上一页
out.print("<script>alert('该用户名已经存在,请换其他名称的用户名!');window.history.go(-1);</script>");
} else {
// 如果查询结果为空,则插入用户数据到 yonghuzhuce 表中
// 获取当前时间
String addtimes = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
String sql = "insert into yonghuzhuce(yonghuming,mima,xingming,xingbie,chushengnianyue,QQ,youxiang,dianhua,shenfenzheng,touxiang,dizhi,beizhu,addtime,issh) values('" + yonghuming + "','" + mima + "','" + xingming + "','" + xingbie + "','" + chushengnianyue + "','" + QQ + "','" + youxiang + "','" + dianhua + "','" + shenfenzheng + "','" + touxiang + "','" + dizhi + "','" + beizhu + "','" + addtimes + "','y') ";
connDbBean.executeUpdate(sql);
// 输出注册成功提示信息,并跳转到 index.jsp 页面
out.print("<script>alert('注册成功!');location.href='index.jsp';</script>");
}
// 关闭 ResultSet 对象
RS_result.close();
阅读全文