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 Method keeps returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Method keeps returning null" Watch "Method keeps returning null" New topic
Author

Method keeps returning null

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi Guys

I have a method which gets some data from the database. Everytime I execute it I get a null exception. I have looked at the code over and cannot find the problem, I have even run the sql statement on the sql server and it returned the expected results. See code below:



error msg:
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

There should be more in the logs than just that. What else does it say?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
abin awale
Greenhorn

Joined: Dec 23, 2008
Posts: 7
Originally posted by shaf maff:
Hi Guys

I have a method which gets some data from the database. Everytime I execute it I get a null exception. I have looked at the code over and cannot find the problem, I have even run the sql statement on the sql server and it returned the expected results. See code below:



error msg:


------------------------------------------------
to use conn.prepareStatement,

first define:
Connection conn = DriverManager.getConnection( )

Hope this helps,
Abin
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
You may still get null in return , as you are closing the connection and then trying to use the Resultset. ResultSet will close as soon you are closing the connection as Resultset is a connected object to db.
The other option may be to use Rowset which is a disconnected version of a Resultset. Or close the connection only when you are done with the ResultSet use.
[ December 23, 2008: Message edited by: raj malhotra ]
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Thanks for th replies guys.
I did a search on rowset and found many different ways to implement it. At the moment I am using the following:

The problem is everytime I compile it I get warnings like the following:

Should I worry about this ?
Is there anyway I can implement it without the worry it might be depreciated in future versions ?
[ December 23, 2008: Message edited by: shaf maff ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Originally posted by shaf maff:
warning: com.sun.rowset.CachedRowSetImpl is Sun proprietary API and may be removed in a future release[/CODE]Should I worry about this ?
Is there anyway I can implement it without the worry it might be depreciated in future versions ?


You would have to retain your current .jar files; it might not be deprecated in future releases, but removed entirely. As you know com.sun packages are "experimental" so if they don't make the grade, they will vanish. If they do make the grade they might be renamed as javax.something packages.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Are there any other methods/classes which doesnt have the same potential fate ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Don't know. There is a CachedRowSet interface; can you persuade your database program to return one of them?
 
Consider Paul's rocket mass heater.
 
subject: Method keeps returning null
 
Similar Threads
consuquences of not closing ResultSet?
How to check record exists
Getting Table Name
Null error
Reading Excel File from a POJO