下面是登陆代码的主要部分,数据库连接都正确,能够从数据库中读出用户名和密码,
也能够判断出用户名是否正确,但问题是判断不了密码的正确,
我把用户的输入和数据库的读出打印出来后,也是一致的,
不知道问题是怎么回事,请大家帮忙看一看
boolean islog=false;
String name,pwd;
name=request.getParameter( "userid" ).trim();
pwd=request.getParameter("pwd").trim();
try{
Connection
con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=airticket","sa","820802");
Statement s=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=s.executeQuery("select * from cuser where name='"+name+"';");
if(!rs.next()){
out.println("<font size=4 color=red>你输入的用户不存在!</font><p>"); }
else{
if(pwd.equals(rs.getString("pwd"))){
session.setAttribute( "theName", ""+rs.getString("name")+"");
out.println(" Hello,");
out.println(session.getAttribute( "theName" ));
islog=true;
}
else{
out.println("<font size=4 color=red>你输入的密码不正确!</font><p>");
session.setAttribute( "thePwd", pwd );
session.setAttribute( "realPwd", ""+rs.getString("pwd")+"");
out.println(" Hello,the pwd you input is:");
out.println(session.getAttribute( "thePwd" ));
out.println("<p> Hello,you pwd of the db is:");
out.println(session.getAttribute( "realPwd" ));
}
}
rs.close();
s.close();
con.close();
}
也能够判断出用户名是否正确,但问题是判断不了密码的正确,
我把用户的输入和数据库的读出打印出来后,也是一致的,
不知道问题是怎么回事,请大家帮忙看一看
boolean islog=false;
String name,pwd;
name=request.getParameter( "userid" ).trim();
pwd=request.getParameter("pwd").trim();
try{
Connection
con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=airticket","sa","820802");
Statement s=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=s.executeQuery("select * from cuser where name='"+name+"';");
if(!rs.next()){
out.println("<font size=4 color=red>你输入的用户不存在!</font><p>"); }
else{
if(pwd.equals(rs.getString("pwd"))){
session.setAttribute( "theName", ""+rs.getString("name")+"");
out.println(" Hello,");
out.println(session.getAttribute( "theName" ));
islog=true;
}
else{
out.println("<font size=4 color=red>你输入的密码不正确!</font><p>");
session.setAttribute( "thePwd", pwd );
session.setAttribute( "realPwd", ""+rs.getString("pwd")+"");
out.println(" Hello,the pwd you input is:");
out.println(session.getAttribute( "thePwd" ));
out.println("<p> Hello,you pwd of the db is:");
out.println(session.getAttribute( "realPwd" ));
}
}
rs.close();
s.close();
con.close();
}
当我输入正确的用户和密码时,上面程序运行的结果是你输入的密码不正确!
Hello,the pwd you input is: wang1 Hello,you pwd of the db is: wang1
login again
String password = rs.getString("pwd");
if ( pwd.equals( password ) ){
}
你好,我刚试了一下,运行结果和原来是一样的
compareTo 我没用过
具体该怎么写啊
看看出来的数据对不!
有可能这句话不对
"select * from cuser where name='"+name+"';"
我把它改成NVARCHAR类型
现在就好使
可是我不知道为什么CHAR类型的就不好使?
把这句SQL语句的冒号去了,加上;不行的。
String password = rs.getString("pwd").toString;试试。