jsp中连接数据库并取出一个字段赋值给一个字符串,然后和一个常量进行比较,输出到页面两个字符串都是“qiao”但进行equals操作,最后显示“false“(不相等)。请问这是什么原因
数据库为SQLServer2000,字段属性为“char”....
多谢!!!!!!!!!!!!!!
conn=Database.getConnection();
stmt=conn.createStatement();
String sql="select * from T_test where name='"+username+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
String temp=(String)rs.getString("password");
out.println(temp);
String rrr=new String("qiao");
out.println(rrr);
if(rrr.equals(passwd))
out.println("success");
else out.println("failed");
}
rs.close();
stmt.close();
conn.close();
}
数据库为SQLServer2000,字段属性为“char”....
多谢!!!!!!!!!!!!!!
conn=Database.getConnection();
stmt=conn.createStatement();
String sql="select * from T_test where name='"+username+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
String temp=(String)rs.getString("password");
out.println(temp);
String rrr=new String("qiao");
out.println(rrr);
if(rrr.equals(passwd))
out.println("success");
else out.println("failed");
}
rs.close();
stmt.close();
conn.close();
}
out.println(temp);
String rrr=new String("qiao");
out.println(rrr);
if(rrr.equals(passwd))——怎么前面的变量名是temp,后面的却是passwd。
偶也曾经用char型,结果被一同事鄙视了半天。- -b
不过偶当时存的是国内的邮政编码,char(6)。
你用下面这个方法就可以了.conn=Database.getConnection();
stmt=conn.createStatement();
String sql="select * from T_test where name='"+username+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
String temp=(String)rs.getString("password");
out.println(temp);
String rrr=new String("qiao");
out.println(rrr);
if(rrr.equals(passwd.trim()))
out.println("success");
else out.println("failed");
}
rs.close();
stmt.close();
conn.close();
}
你用下面这个方法就可以了.conn=Database.getConnection();
stmt=conn.createStatement();
String sql="select * from T_test where name='"+username+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
String temp=(String)rs.getString("password");
out.println(temp);
String rrr=new String("qiao");
out.println(rrr);
if(rrr.equals(temp.trim()))
out.println("success");
else out.println("failed");
}
rs.close();
stmt.close();
conn.close();
}