qq_40445897
qq_40445897
2017-10-14 07:39

关于if(rs.next()){}else{},每次运行直接显示else分支的语句,求帮忙

  • java
  • jdbc
  • sql

<%

   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); //加载驱动、
   String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=liuben";
   String user="sa";
   String password="961213";
   Connection conn= DriverManager.getConnection(url,user,password);

   PreparedStatement stmt1=conn.prepareStatement("select * from t_user where username=?");
   PreparedStatement stmt=conn.prepareStatement("insert into t_user values(?,?)");
   String c=request.getParameter("name");
   String a=request.getParameter("name");
   String b=request.getParameter("psword");
   stmt.setString(1,a);
   stmt.setString(2,b);
   stmt1.setString(1,c);

   ResultSet rs=stmt1.executeQuery();
     if(rs.next()){
             out.print("用户名已存在,请使用其他的用户名");
                     }else{
                        int i=stmt.executeUpdate();
                        out.print("注册成功");
                                 }
         }

         conn.close();      

%>

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答