Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Closing JDBC Connections in Pool
- Connection conn = getConnection(...);
- Statement stmt = conn.conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet rset = stmt.executeQuery (sqlQuery);
- // do stuff with rset
- rset.close(); stmt.close(); conn.close();
- synchronized public Connection getConnection (boolean pooledConnection)
- throws SQLException {
- if (pooledConnection) {
- if (ds == null) {
- try {
- Context envCtx = (Context)
- new InitialContext().lookup("java:comp/env");
- ds = (DataSource) envCtx.lookup("jdbc/NamedInTomcat");
- return ds.getConnection();
- } catch (NamingException e) {
- e.printStackTrace();
- }}
- return (ds == null) ? getConnection (false) : ds.getConnection();
- }
- return DriverManager.getConnection(
- "jdbc:mysql://"+ipaddy+":"+dbPort +"/" + dbName, uName, pWord);
- }
- synchronized public Connection getTomcatConnection () {...}
- public Connection getCustomConnection() {...}
- public void close() throws SQLException {
- pool.returnConnection(this);
- }
Add Comment
Please, Sign In to add comment