wood burning stoves 2.0*
The moose likes JDBC and the fly likes Will jdbc Prepared Statement's executeQuery ever return null. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Will jdbc Prepared Statement Watch "Will jdbc Prepared Statement New topic
Author

Will jdbc Prepared Statement's executeQuery ever return null.

Shankar Raj
Greenhorn

Joined: Aug 26, 2008
Posts: 4
Though Java API says never null. People generally check if (rs!=null) rigt after some rs=ps.executeQuery();
just curious will ever they get rs==null say db was not connecting etc. I presume it would throw exceptions and will never encounter such situations but why do people write this?


Regards,<br />Shankar Raj.J
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Shankar Raj wrote:People generally check if (rs!=null) rigt after some rs=ps.executeQuery();

Generally ? Only people who don't read the API do.

[edited to fix quote marks]


[My Blog]
All roads lead to JavaRanch
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

Christophe is 100% correct. executeQuery() does not return null. Checking for null is poor practice and not considered a JDBC idiom.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Will jdbc Prepared Statement's executeQuery ever return null.
 
Similar Threads
Avatar support?
returning a result set
Unable to save a file using JFileChooser
How to check record exists
Problem with rs.isAfterLast() and rs.isFirst()