Please help me to see if I "set" and "return" the number of records in my database table correctly (I am using the Oracle 9i):
public int getNumberOfRecipientBeans() throws AssertionException, DatabaseException
{
Connection conn = null;
PreparedStatement stmt = null;
String query = "SELECT count(*) FROM ContactEntry WHERE ContactTypeID = 6";
ResultSet rs = null;
try
{
conn = DBConnection.getDBConnection();
stmt = conn.prepareStatement( query );
rs = stmt.executeQuery();
// do I have to set anything here?
if ( !rs.next() )
{
throw new AssertionException("Assertion in servuce.getNumberOfRecipients");
}
// Am I returning the counts here?
return rs.getInt( 1 );
}
catch( SQLException sqle )
{
sqle.printStackTrace();
throw new DatabaseException( "Error executing SQL in service.getNumberOfRecipients." );
}
finally
{
if ( conn != null )
{
try
{
stmt.close();
stmt = null;
conn.close();
}
catch( Exception Ex )
{
System.out.println( "Problem occurs while closing " + Ex );
}
conn = null;
}
}
}