当前位置: 代码迷 >> Java Web开发 >> 请帮忙看看这段代码,不要笑小弟我,初学.多谢
  详细解决方案

请帮忙看看这段代码,不要笑小弟我,初学.多谢

热度:88   发布时间:2016-04-17 14:55:02.0
请帮忙看看这段代码,不要笑我,初学.谢谢!
代码如下:目的是注册。想要两次输入的密码一致后,到数据库中的TBL_STU表中查找是否重名,如果不重名,插入表中。
if(pwd.equals(repwd))
{
       
      ResultSet   rs1=sql.executeQuery( "select   *   from   TBL_STU   where   xh= ' "+xh+ " ' ");
     
      //out.print(sql1);
              if(rs1.next())
      {
      rs1.close();
out.print( " <script> alert( '该用户名已经被注册,请选择其它的用户名! '); </script> ");
}
      else{      
               
                        try
                                {
sql.executeUpdate( "insert   into   TBL_STU(xh,xm,bh,pwd,sex,nl,zy,sfzh,txdz,yb,dh,email)   values( ' "+xh+ " ', ' "+xm+ " ', ' "+bh+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+nl+ " ', ' "+zy+ " ', ' "+sfzh+ " ', ' "+txdz+ " ', ' "+yb+ " ', ' "+dh+ " ', ' "+email+ " ') ");
                                }
                        catch(SQLException   e1)  
                                      {
                                        out.print(e1.getMessage());
                                      }
                                }

}

------解决方案--------------------
sql.executeUpdate( "insert into TBL_STU(xh,xm,bh,pwd,sex,nl,zy,sfzh,txdz,yb,dh,email) values( ' "+xh+ " ', ' "+xm+ " ', ' "+bh+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+nl+ " ', ' "+zy+ " ', ' "+sfzh+ " ', ' "+txdz+ " ', ' "+yb+ " ', ' "+dh+ " ', ' "+email+ " ') ");


你用其他方式单调用这句话.看看能不能插.有可能字段验证不通过
------解决方案--------------------
if(pwd.equals(repwd))
{

ResultSet rs1=sql.executeQuery( "select * from TBL_STU where xh= ' "+xh+ " ' ");

//out.print(sql1);
System.out.println( "select * from TBL_STU where xh= ' "+xh+ " ' ");/////////加这一句进去看看
if(rs1.next())
{
rs1.close();
out.print( " <script> alert( '该用户名已经被注册,请选择其它的用户名! '); </script> ");
}
else{

try
{
System.out.println( "insert into TBL_STU(xh,xm,bh,pwd,sex,nl,zy,sfzh,txdz,yb,dh,email) values( ' "+xh+ " ', ' "+xm+ " ', ' "+bh+ " ', ' "+pwd+ " ', ' "+sex+ " ', ' "+nl+ " ', ' "+zy+ " ', ' "+sfzh+ " ', ' "+txdz+ " ', ' "+yb+ " ', ' "+dh+ " ', ' "+email+ " ') ");/////////加这一句进去看看
  相关解决方案