• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

ResultSet is coming null  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there coderanch folks!

It's always a pleasure to be a member of here!

I have a problem: In my method which is called by another method, i have a ResultSet which is coming up as Null, even after i got the data from database.

Overview:

My class:



One of my two methods which is called as first:



my whole second method which ResultSet is null:



The class and method i'm using to test it on the web:



Problems occured during the debugging(test):

stm.setString(1, idProcess); //idProcess = "3756" (id=114) hash = 0 value = (id=378)
rs = stm.executeQuery();  //Name: setString() returned. Value: (No explicit return value)
rs.next(); //true

String idProcess = rs.getString("IDPROCESS"); //has values inside
String nmProcess = rs.getString("NMPROCESS"); //has values inside
String cdUserStart = rs.getString("CDUSERSTART"); //has values inside
Long vlTimeFinish = rs.getLong("VLTIMEFINISH"); //has values inside
String dsProcess = rs.getString("DSPROCESS"); //has values inside
String nmProcessModel = rs.getString("NMPROCESSMODEL"); //has values inside

... if (hasResultData(rs) == true) { //it shows: false.   (Why false if i got data inside the RS?)

It seems the idProcess that will be setted through setString(1, idProcess) is right, but ResultSet return is null(empty). This is the problem i'm gettin of.

I would appreciate so much if somebody could help me in this quest.

Thank you.

 
Rancher
Posts: 3737
40
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the method hasResultData do?
You haven't posted that one (unless I'm being blind, which is not unheard of).

Edit:  Also, why are you checking whether there is data?
You already know that as you have extracted it.
If there was no data then the code would have thrown an exception the first time you tried to do rs.getString().

The normal structure for this would be:
 
Saloon Keeper
Posts: 5136
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From another of the OP's threads
 
Dave Tolls
Rancher
Posts: 3737
40
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah right.
So, since next() has already been called then isBeforeFirst() will return false.

I suggest not using that method and simply use the boolean returned by the call to next() to determine if there's any data.  That's what it is for.

Also, the ResultSet returned by executeQuery() will not be null, so don't bother checking it.
 
Bruno Joao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks folks! It worked. But, i've changed some things in my code and it's not working yet. I'm gonna post it here, but if needed to open another new post, just let me know. Thanks!

My class and method to test it via web:





Switch goes to Case 2.
I'm getting java.lang.NullPointerException on *while (rs2.next())*.

Any help/suggestion will be welcome.

Thanks again coderanch. I luv ya!

Bruno
 
Carey Brown
Saloon Keeper
Posts: 5136
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
 
Dave Tolls
Rancher
Posts: 3737
40
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this was commented on in the other thread, bu that's a really long (and confusing) method.

Aside from that, if the first query does not return any results you will get an exception on this line:

as there is no row to get a value from.
 
Bruno Joao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:I think this was commented on in the other thread, bu that's a really long (and confusing) method.

Aside from that, if the first query does not return any results you will get an exception on this line:

as there is no row to get a value from.



Hi,

I'm gonna check this later. Thanks for the help.
 
Bruno Joao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After these suggestions to fix the problem, my code is working now.

I'm very greatful for your help, guys.

Thank you very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!