File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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: 14688
    
  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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

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.