下面是登陆代码的主要部分,数据库连接都正确,能够从数据库中读出用户名和密码,
也能够判断出用户名是否正确,但问题是判断不了密码的正确,
我把用户的输入和数据库的读出打印出来后,也是一致的,
不知道问题是怎么回事,请大家帮忙看一看
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();
}
解决方案 »
- 急求利用java弹出一个图案
- ACM试题,高精度,怎么用java实现
- (环境:linux+apache+php5)想把函数中“总计”的值显示为checkbox选中后的文件大小的总和,测试时提示: ftrs = document.getElementByName('file_list[]');(是取checkbox)不合法?
- 设置控件失去焦点问题?
- java连接池驱动问题
- java中的空格
- 请高手过来看看,本人有一个难题请大家帮帮忙
- 请教个问题 关于Applet 大虾多帮忙啊!!
- 怎样初始化对象的static数据成员?
- String类型数据与Date类型转换的问题?
- 为什么这两个键有时候会失效?求解
- java 怎样取得一个图片的尺寸
当我输入正确的用户和密码时,上面程序运行的结果是你输入的密码不正确!
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;试试。