Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The ResultSet

 
Bhavik patel
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()?
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
false will be returned if the resultset object has no rows.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'";
 
mnadeem chishti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic