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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Determining null resultset" Watch "Determining null resultset" New topic
Author

Determining null resultset

Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
Hi - I have my application working and I am now validating user input etc. This application takes the text output of a genetics test and inserts the rows into a Oracle DB. Part of this process requires that I check that a locus name is currently in the database and then look up some genetic information. I am trying to determine if the resultset is null because there was no record. Ie if the text value is "One_CytB26" and the value in the database is "One_CytB_26" then I would expect a null resultset. But how do I check it? Thanks for any help you can give.

private void LookupLocus(String strLocusName)
{
// this method does a db lookup for each locus to determine the appropriate allele values
try
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
String url = "jdbc racle:thin:@db-dbname";
Connection conn = DriverManager.getConnection(url,"usr","pwrd");
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM AKFINADM.LOCUS_LOOKUP WHERE LOCUS_NAME = '" + strLocusName + "'" );
if(rset == null)
{
JOptionPane.showMessageDialog(null,"There is a locus error.","SQL Error",JOptionPane.ERROR_MESSAGE);
}
while(rset.next())
{
strPloidy = rset.getString("PLOIDY");
strGenome1 = rset.getString("BOTH_GENOTYPE_1");
strGenome2 = rset.getString("BOTH_GENOTYPE_2");
}
rset.close();
conn.close();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"There is a database error.","SQL Error",JOptionPane.ERROR_MESSAGE);
return;
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
[ May 21, 2004: Message edited by: Steve Gebert ]
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
The ResultSet will never be null, regardless of whether or not any records were found. A simple implementation of checking the number of records returned is to use an int counter. So, for instance:
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
If you only expect a single result back, you can use this syntax as well.

[ May 21, 2004: Message edited by: Wayne L Johnson ]
Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
That worked great! I guess I'm still a little used to VB. I appreciate your response, thank you.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the JDBC forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Srinivas Gogineni
Greenhorn

Joined: May 06, 2004
Posts: 6
hi,
You can try using the wasNull method of the resultset
rs.wasNull();

Thx and regards
-Srini
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determining null resultset