This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes The ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "The ResultSet" Watch "The ResultSet" New topic
Author

The ResultSet

Bhavik patel
Ranch Hand

Joined: Feb 20, 2007
Posts: 49
Hello Friends,


I am new to JDBC....

String query="SELECT * FROM Login WHERE username="+"bhavik";

now suppose,if the user name "bhavik" does not exist...
what will be returned by the method stmt.executeQuery(query);?
and i knoew it will be anythingf except null...

what will be returned by rs.next()?


Bhavik Patel
Glassfish Consultancy service At http://www.jmatrix.in
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
false will be returned if the resultset object has no rows.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Bhavik,
If a SQL statement is valid and doesn't match anything, JDBC returns an empty result set. This means that rs.next() returns false.

Note that the SQL in your example is not considered valid by most databases. It needs single quotes around the value:
String query="SELECT * FROM Login WHERE username='bhavik'";


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
mnadeem chishti
Greenhorn

Joined: Aug 07, 2006
Posts: 11
Originally posted by Bhavik patel:
Hello Friends,


I am new to JDBC....

String query="SELECT * FROM Login WHERE username="+"bhavik";

now suppose,if the user name "bhavik" does not exist...
what will be returned by the method stmt.executeQuery(query);?
and i knoew it will be anythingf except null...

what will be returned by rs.next()?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The ResultSet
 
Similar Threads
Question from John Meyer's Mock
problem in static
Assertion
EJB3.0 on JBOSS 5.0 Deployment problem
simple program