try{
Statement h1=conn.createStatement();
ResultSet rs=h1.executeQuery("select password from cp_people where ID='"+t1.getText().toString().trim()+"'");
String password;
while(rs.next()){
password=rs.getString(1).trim();
System.out.println(password);
if(password.equals(jp.getPassword().toString().trim())==true){
System.out.println("哈哈");
JOptionPane.showMessageDialog(null, "用户名和密码正确正确正确正确正确正确!");
try{
System.out.println("Hello, " + ". Next year, you'll be " );
}
catch(Exception e2) {
e2.printStackTrace();
}
finally {
System.exit(0); }
break;
}
else
{
JOptionPane.showMessageDialog(null, "用户名和密码错误") ;
try{
System.out.println("Hello, " + ". Next year, you'll be " );
}
catch(Exception e1) {
e1.printStackTrace();
}
finally {
System.exit(0); }
}
}
} catch(Exception v) {
v.printStackTrace();
}
}
这段代码,执行时,没发生任何错误
我输入用户名和密码时,无论输入什么都显示用户名和密码错误。请问各位高手,我哪错了?谢谢!
Statement h1=conn.createStatement();
ResultSet rs=h1.executeQuery("select password from cp_people where ID='"+t1.getText().toString().trim()+"'");
String password;
while(rs.next()){
password=rs.getString(1).trim();
System.out.println(password);
if(password.equals(jp.getPassword().toString().trim())==true){
System.out.println("哈哈");
JOptionPane.showMessageDialog(null, "用户名和密码正确正确正确正确正确正确!");
try{
System.out.println("Hello, " + ". Next year, you'll be " );
}
catch(Exception e2) {
e2.printStackTrace();
}
finally {
System.exit(0); }
break;
}
else
{
JOptionPane.showMessageDialog(null, "用户名和密码错误") ;
try{
System.out.println("Hello, " + ". Next year, you'll be " );
}
catch(Exception e1) {
e1.printStackTrace();
}
finally {
System.exit(0); }
}
}
} catch(Exception v) {
v.printStackTrace();
}
}
这段代码,执行时,没发生任何错误
我输入用户名和密码时,无论输入什么都显示用户名和密码错误。请问各位高手,我哪错了?谢谢!
然后再把jp.getPassword().toString().trim()打出来看看.这样简单的调试就知道了
Statement h1=conn.createStatement();
ResultSet rs=h1.executeQuery("select password from cp_people where ID='"+t1.getText().toString().trim()+"'");
String password;
while(rs.next()){
password=rs.getString(1).trim();
System.out.println(password);
if(password.equals(jp.getPassword().toString().trim())==true){
System.out.println("哈哈");
JOptionPane.showMessageDialog(null, "用户名和密码正确正确正确正确正确正确!");
try{
System.out.println("Hello, " + ". Next year, you'll be " );
}
catch(Exception e2) {
e2.printStackTrace();
}
finally {
System.exit(0); }
break;
}
else
{
JOptionPane.showMessageDialog(null, "用户名和密码错误") ;
try{
System.out.println("Hello, " + ". Next year, you'll be " );
}
catch(Exception e1) {
e1.printStackTrace();
}
finally {
System.exit(0); }
}
}
} catch(Exception v) {
v.printStackTrace();
}
}
lz可以改成
String tmp = new String(jp.getPassword());
if( password.equals(tmp.trim()) ) {
.
.
.
}
另外建议你贴代码的时候用下面的插入源代码功能,那样要容易看!!