代码:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bbs","sa","");Statement stmt=con.createStatement();ResultSet rst=stmt.executeQuery("select * from userinfo where user=\'"+user+"\' and pwd=\'"+pwd+"\'");

解决方案 »

  1.   

    ResultSet rst=stmt.executeQuery("select * from userinfo where user='"+user+"' and pwd='"+pwd+"'");
    这样写才对
      

  2.   

    ResultSet rst=stmt.executeQuery("select * from userinfo where user='"+user+"' and pwd='"+pwd+"'");
    这句是对的,不过你要注意这种用户名与密码验证方式有漏洞,你在你的用户名和密码栏输入''or'='看看,是不是直接进去了,所以用户名和密码验证最好采用分段验证,先验证用户名是否存在,再验证密码是否正确。
      

  3.   

    to:xiangbo520(真诚到永远)
    呵呵,这个我知道,我只是写一个测试连接的程序,我想问为什么会出现错误java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection reset 是这句Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bbs","sa","");
    错了,我不知道怎么会事.