给你一个建议,用username和password这两个字段的数据库中同时找,这样估计不会出问题,也就是你的sql语句改成 string sql="select * from user where username=? and password=?"; pstmt=conn.prepareStatement(sql); pstmt.setString(1,userName); pstmt.setString(2,password); rs=pstmt.executeQuery(); return rs.next(); 将check()方法改成返回boolean类型的,参数不变。估计你的问题是出在pstmt和rs己经被使用一次了,可能己经失效了,如果不行的话,你在你的那个else中另外声明一个pstmt和rs试试看。
sql="select * from userinfo where loginid='"+userName+"'and passwd=?"; 注意and前面需要一个空格! sql="select * from userinfo where loginid='"+userName+"' and passwd=?";
注意and前面需要一个空格! sql="select * from userinfo where loginid='"+userName+"' and passwd=?"; ======================================== 试过了,不行.
string sql="select * from user where username=? and password=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,userName);
pstmt.setString(2,password);
rs=pstmt.executeQuery();
return rs.next();
将check()方法改成返回boolean类型的,参数不变。估计你的问题是出在pstmt和rs己经被使用一次了,可能己经失效了,如果不行的话,你在你的那个else中另外声明一个pstmt和rs试试看。
sql="select * from userinfo where loginid='"+userName+"' and passwd=?";
sql="select * from userinfo where loginid='"+userName+"' and passwd=?";
========================================
试过了,不行.
PreparedStatement 的方法 executeQuery() 没有参数pstmt=conn.prepareStatement(sql);
pstmt.setString(1,password) ;
rs=pstmt.executeQuery() ;