• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Method keeps returning null

 
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:
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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?
 
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
 
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 ]
 
Marshal
Posts: 64704
225
  • 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
Marshal
Posts: 64704
225
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!