Win a copy of Head First Android this week in the Android forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

result null is null(urgent help)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have inserted fields in my oracle database using :
insert into table values('test','test',NULL);
when I try to retreive all the rows where the last field is NULL, if there are no rows returned ,how do I check for that condition.
I tried using if(ResultSet ==null),
tried using if (RS1.isBeforeFirst())
Nothing works,
Pls help!!!
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shilpabijam:
I have inserted fields in my oracle database using :
insert into table values('test','test',NULL);
when I try to retreive all the rows where the last field is NULL, if there are no rows returned ,how do I check for that condition.
I tried using if(ResultSet ==null),
tried using if (RS1.isBeforeFirst())
Nothing works,
Pls help!!!


------------------------------------
simple
add this to ur code
if(resultset != null)
{
if(!resultset.next()) System.out.println("No rows retrieved ..");
else
{
while(resultset.next())
{
//dosomething
}
}

bye!
 
Hrithik Roshan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hrithik Roshan:


int i = resultset.executeUpdate()
if(i > 0) System.out.println("Success...")
else
System.out.println("Error: ");

------------------
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With regards to the code from Hrithik Roshan, the first version is wrong (it will detect if there aren't any results correctly, but if there it discards the first result!) and the second returns the number of rows inserted...
Maybe what you want is more like:

Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"shilpabijam",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.
Dave
 
Hrithik Roshan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:
[B]With regards to the code from Hrithik Roshan, the first version is wrong (it will detect if there aren't any results correctly, but if there it discards the first result!) and the second returns the number of rows inserted...
Maybe what you want is more like:

Dave[/B]


well Dave!
i think i can do this way!
--------------------------------------------
if(resultset != null)
{
if(!resultset.next()) System.out.println("No rows retrieved");
else
{
while(resultset.next())
{
//dosomething
}
}
else
{
System.out.println("ResultSet is null ...");
}
------------------
 
Hrithik Roshan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:
[B]With regards to the code from Hrithik Roshan, the first version is wrong (it will detect if there aren't any results correctly, but if there it discards the first result!) and the second returns the number of rows inserted...
Maybe what you want is more like:

Dave[/B]


well Dave!
i think i can do this way!
--------------------------------------------
if(resultset != null)
{
if(!resultset.next()) System.out.println("No rows retrieved");
else
{
while(resultset.next())
{
//dosomething
}
}
}
else
{
System.out.println("ResultSet is null ...");
}
------------------
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just a little heads up for you in your:
by the time you start processing your results in the while loop, you have called rs.next() twice. This means that you will start processing on the second record, missing out on the first. In Daves example, after calling the first rs.next() he processes the first record, then proceeds to the while loop to process the rest.
Also, the jdbc specs say that the resultset returned by statement.executeQuery() will never be null. a resultset will always be created (just empty). So the condition if(rs==null) will never occur(unless your driver does not follow the JDBC specifications). If there is a problem creating the resultset then a SQLException will be thrown and it will skip the remaining code anyways.
This link also discussed this problem in depth. There are many ways to check if a resultset has returned any results. Choose the one that best fits your program: http://www.javaranch.com/ubb/Forum3/HTML/001904.html
Jamie
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic