I want to re-use a java.sql.Connection object. It is with Google App Engine so connection pooling is not an option (I think?). Normally I just create a new connection per servlet call, but now I have functions being called from the servlet and I don't want to create a new connection on each function call (unless I know it will be very fast), e.g.
public void someServlet() { // Called from web page - speed is thus of concern
try (Connection con = DriverManager.getConnection("connection string")) { // might be slow - want to re-use con
// Do something with connection, e.g. run some queries
someSQLFunction();
someSQLFunction();
someSQLFunction();
} catch (SQLException e) {
// Some error handling
}
}
public void someSQLFunction() throws SQLException {
// I don't want to re-create another Connection here, but use the one from the servlet.
try (Connection con = DriverManager.getConnection("connection string")) { // might be slow - want to re-use con
// Do something with connection, e.g. run some queries
return;
}
}
How can I re-use the Connection object of the servlet within someSQLFunction()?