Hi..i have created a common method for all my SelectQueries from the Data-Base.
--------------------------------------------------------------------
public void selectQuery(
String saQuery, ResultSet objaResultSet) throws SQLException {
/* Connection Object */
Connection objlConnection = null;
/* Prepared Statement */
PreparedStatement objlPreparedStatement = null;
try {
objlConnection = getConnection();
/* Preparing Statement*/
objlPreparedStatement = objlConnection.prepareStatement(saQuery);
/* Executing Query*/
objaResultSet = objlPreparedStatement.executeQuery();
PFNLog.log("\nQuery executed: " + saQuery, DRRUtils.DRR_DEBUGON);
} catch (Exception objaException) {
PFNLog.log("Exception in selectQuery.", DRRUtils.DRR_DEBUGON);
PFNLog.logException(objaException);
/* Throwing SQLException to the calling method */
throw new SQLException();
} finally {
/* Closing the PreparedStatement */
try {
if (objlPreparedStatement != null) {
objlPreparedStatement.close();
}
} catch (Exception objaException) {
PFNLog.logError("Exception in closing PreparedStatement in " + this.getClass());
PFNLog.logException(objaException);
}
/* Closing the Connection Object */
if (objlConnection != null) {
closeConnection(objlConnection);
}
}
}
--------------------------------------------------------------------
Earlier i was creating a New ResultSet Object in this method itself.However i had to Return this ResultSet Object to the calling method.
To avoid this i recreated the method to pass a Reference of the ResultSetObject(created now in the calling method).However the problem is now when i close the PreparedStatement and Connection Object the ResultSet Object becomes null also
Now i must implement this comman method and Must have a ResultSet Object to iterate through in the calling method...
Guys please suggest a better way to solve this.And please let me know the reason for choosing also..
-Thanks-