This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Quering the ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Quering the ResultSet" Watch "Quering the ResultSet" New topic

Quering the ResultSet

kunal Jaggi

Joined: Jun 17, 2003
Posts: 1
I am using Tomcat 4.1.12 on Windows 2000 professional. I am using the JDBC-ODBC Bridge driver to access the MS Access Database. I am having a problem while quering the ResultSet. Following is the code snippet that gives the problem :-
rs=st.executeQuery("SELECT * FROM Users WHERE cID='"+f.getUserName()+"'");
}catch(SQLException e){
I have checked the database, I know that there is no user id foe example “kunal”- even then the boolean variables evaluates to true. Can we query the ResultSet like that?
Kunal Jaggi
Sun Certified Java 2 Programmer
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Java Facier,
Welcome to JavaRanch! We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks pardner. Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
The ResultSet object returned by executeQuery() is never null. If there are no matching records, an empty ResultSet is returned.
Thus, you need to do something like this instead:

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Thanks for changing your display name. Now, if you could just replace the underscore with a space, our naming policy would be satisfied.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32819

The above example, could even be shorter. Checking for an empty result set is fast and easy.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Kunal Goel

Joined: Sep 08, 2002
Posts: 16
Thanks Lasse and Jeanne, it was something very obvious that I missed.
I agree. Here's the link:
subject: Quering the ResultSet
jQuery in Action, 3rd edition