Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to use connection pooling outside servlet engine
    primarykey
    data
    text
    <p>I have a series of methods running within a servlet engine (Tomcat in this case), using connection pooling to access the database written in this way:</p> <pre><code>// Gets an RSS_Feed. public static RSS_Feed get(int rssFeedNo) { ConnectionPool_DB pool = ConnectionPool_DB.getInstance(); Connection connection = pool.getConnection(); PreparedStatement ps = null; ResultSet rs = null; String query = ("SELECT * " + "FROM RSS_Feed " + "WHERE RSSFeedNo = ?;"); try { ps = connection.prepareStatement(query); ps.setInt(1, rssFeedNo); rs = ps.executeQuery(); if (rs.next()) { return mapRSSFeed(rs); } else { return null; } } catch(Exception ex) { logger.error("Error getting RSS_Feed " + rssFeedNo + "\n", ex); return null; } finally { Database_Utils.closeResultSet(rs); Database_Utils.closeStatement(ps); pool.freeConnection(connection); } } </code></pre> <p>Is it possible to call such a method outside of the servlet engine at all? I would like to do this in a batch process executed from the command line instead of within the servlet engine. I know I could simply rewrite the query without connection pooling but this is one of many queries involved in the process.</p> <p>The connection pooling is implemented via Apache Common DBCP. </p> <p><strong><code>ConnectionPool_DB.getInstance();</code> reads:</strong></p> <pre><code>private ConnectionPool_DB() { try { InitialContext ic = new InitialContext(); dataSource = (DataSource) ic.lookup(PropertiesFile.getProperty("myApp", "DATASOURCE")); // dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/myApp"); } catch(Exception ex) { logger.error("Error getting a connection pool's datasource\n", ex); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload