• Post Reply Bookmark Topic Watch Topic
  • New Topic

Login problem

 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a table in a database.
table= System_User ( got Username and Password)
database = CineHomeV2

here is my coding:
------------------------

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn= DriverManager.getConnection("jdbc dbc:CineHomeV2");
Statement ss= cn.createStatement();
ResultSet rs=ss.executeQuery("SELECT * FROM System_User");

while(rs.next()){
if(username.getText().equals(rs.getString(1)) && new String(password.getPassword()).equals(rs.getString(2)))
{
JFrame.setDefaultLookAndFeelDecorated(true);
CineHome ch=new CineHome();ch.setDefaultCloseOperation(EXIT_ON_CLOSE);
ch.show();
setVisible(false);
}else{
JOptionPane.showMessageDialog(this,"Invalid Username or Password","Invalid Entry" ,JOptionPane.ERROR_MESSAGE);
username.setText("");
password.setText("");
break;
}


} // end while
} // end try
----------------------------------------------
i use if-else inside while loop, and it cannot work and it keep give me the JOptionPane defined in the else block. I key in the correct username and password (same exactly as data defined in table System_User), it will keep give me else block .

but when i delete the else block, and i key in the correct username and password, well, it works.

I wanna put else blcok because i want when one of the entry was wrong, then it display the else block message.

anyone could help me???
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding these lines just before the while loop. They should help you see what the program is comparing:
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot put infront ot whiel loop, because the rs.next() is in the while loop.

if follow what you said, will get a cursor invalid state.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I see that now. Well anyway you can put it just after the while. The if line will then fail, but that doesn't matter because it will have executed the println statements, which is all you want.
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, i realised that too...hehe

well i try to solve this problem after i finish the rest of the system modules.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!