This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method keeps returning null

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be more in the logs than just that. What else does it say?
 
abin awale
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48415
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any other methods/classes which doesnt have the same potential fate ?
 
Campbell Ritchie
Sheriff
Posts: 48415
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. There is a CachedRowSet interface; can you persuade your database program to return one of them?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic