When running this code, I get a ResultSet closed error. The called methods and data are as follows:
Log output:
[2014-05-05 22:34:09.169 Debug] select count(*) as total from companies
[2014-05-05 22:34:09.170 Debug] ResultSet closed
Methods:
public static Boolean recordsExist(String string, Connection c) {
try {
String[] query = string.split("\\*");
String sql = "select count(*) as total" + query[1];
ResultSet resultset = queryDB(sql, c);
resultset.next();
int count = resultset.getInt(1);
Log.debug(Integer.toString(count));
resultset.close();
if (count > 0) {
Log.debug("recordsExist returning true");
return true;
} else {
Log.debug("recordsExist returning false");
return false;
}
} catch (Exception e) {
Log.debug(e.getMessage());
return false;
}
}
public static ResultSet queryDB(String sql, Connection c) throws SQLException {
Log.debug(sql);
Statement s = c.createStatement();
ResultSet resultset = s.executeQuery(sql);
s.close();
return resultset;
}
Sql string specified:
select * from companies