Here's the JdbcRowSetImpl implementation of close
public void close() throws SQLException {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (conn != null)
conn.close();
}
Since the JdbcRowSetImpl.close() will close the connection, the best way to fit with your current architecture might be to create a JdbcRowSet member or instance singleton that is closed when you expect the connection to be classed. Your function1 and function2 would look like this
public static Connection conn = DBConnection.getInstance()
.getConnection();
//Implementation of DBRowSet left as an exercise for the ambitious.
public static JdbcRowSet myrs = DBRowSet.getInstance();
private static void function1() {
try {
myrs.setCommand("SELECT * FROM `table1`");
myrs.execute();
//result iteration
} catch (SQLException e) {
e.printStackTrace();
}
}
private static void function2() {
try {
myrs.setCommand("SELECT * FROM `table2`");
myrs.execute();
//result iteration
} catch (SQLException e) {
e.printStackTrace();
}
}