Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Select From Where Clause using JDBC

 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranch,
I am developing standalone GUI bank application
in the log in window the action i am trying to perform for the jButton1 is that when the user enters the UserId and Password and hit the Submit Button the following is expected
1)the database i am using is MsAccess 2007
2) when user hits the submit button then userid and password should be search and if it is there then user gets to next window
3)otherwise a dialog box should be displayed

But the result i am getting
1) when the user enters the UserId and Password and hit the Submit Button i am not getting the desired output because i think the sql query i am using is not executing at all.

SQL Query----("Select UserID,Password "+"From LoginInformation where UserID='"+i+"' and Password='"+j+"'");

kindly suggest on this and also the flaw if any is there in query


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String i = jTextField1.getText();
String j = jTextField2.getText();
try {
pstmt = con.prepareStatement("Select UserID,Password "+"From LoginInformation where UserID='"+i+"' and Password='"+j+"'");
/*pstmt.setString(1, i);
pstmt.setString(2, j);*/
rs = pstmt.executeQuery();
while (rs.next()) {
if (rs.getString(1).equals(i) && rs.getString(2).equals(j)) {
HomePage hp = new HomePage();
hp.setVisible(true);
close();
} else if (i.isEmpty() || j.isEmpty()) {
JOptionPane.showMessageDialog(null, "UserId and password cannot be left blank.");

} else {
JOptionPane.showMessageDialog(null, "Enter Correct UserId and Password");
}
}
} catch (Exception e) {
}
}

Thanks
 
E Armitage
Rancher
Posts: 989
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.) Don't do

At least do

to see if there are exceptions being thrown.

2.) Don't add string using + for sql statement parameters. Use PreparedStatement parameters instead to set the values.
3.) Read up on swing and threading to find out how to use swing without performing long running or IO operations on the EDT.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic