File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL Query using WHERE clause. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Query using WHERE clause." Watch "SQL Query using WHERE clause." New topic

SQL Query using WHERE clause.

Rose Jac
Ranch Hand

Joined: May 20, 2011
Posts: 33

I am trying to implement this method, but the where clause in the sql seems to be not working. My database has the fields : ID, lastName, firstName, mi, address, city, state, telephone, email with 2 records.
The code attempts to display a specific record whose id is entered by the user in a JApplet's Textfield and then, the other fields of the reocrd corresponding to that id is displayed on the other textfields on clicking the 'View' JButton.
Do help.

Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
Is it throwing an exception? Even if it throws an exception you will never know that unless you run debugger and step line by line through the code because you have a empty catch block.

Also probably you want to use a PreparedStatement instead of Statement.
Tim Moores

Joined: Sep 21, 2011
Posts: 2413
Is "ID" really a varchar field? You're surrounding it with single quotes as if it were...

Yet another reason to get in the habit of using PreparedStatement.
Rose Jac
Ranch Hand

Joined: May 20, 2011
Posts: 33
Thank you very much! That worked.
I agree. Here's the link:
subject: SQL Query using WHERE clause.
jQuery in Action, 3rd edition