• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Select From Where Clause using JDBC

 
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic