Note that there are some explanatory texts on larger screens.

plurals
  1. POjava c3po statement for every query
    primarykey
    data
    text
    <p>I am a beginner in JDBC and in my research i find best review on C3PO as i already tried BoneCP, only to find it doesn't close connections.</p> <p>I need a connection pool, maybe also a statement pool, for a multithreading soft real time software (trading system)</p> <p>This is an example of "SELECT":</p> <ol> <li>is it good?</li> <li>do i need to getConn() and then create statement and close both for every query?</li> <li><p>any general comments or suggestions?</p> <pre><code> Connection conn = null; ResultSet rs = null; Statement st = null; String query = null; try { query = " SELECT id " + " FROM " + DBTables.PandaSources; //rs = DB.ConnPool.invoke(conn, query, rs); st = DB.ConnPool.getSt(); rs = st.executeQuery(query); if (rs != null) { while (rs.next()) { ..... ...... } } } catch (Exception e) { e.printStackTrace(); Util.logException(e); } finally { if (rs != null) try { rs.close(); } catch (SQLException e) { e.printStackTrace(); Util.logException(e); } if (st != null) try { st.close(); } catch (SQLException e) { e.printStackTrace(); Util.logException(e); } if (conn != null) try { conn.close(); } catch (SQLException e) { e.printStackTrace(); Util.logException(e); } } query = null; st = null; rs = null; conn = null; } public static synchronized Statement getSt() throws SQLException { return getConn().createStatement(); } public static synchronized Connection getConn() throws SQLException { if (connectionPoolDatasource == null) { initPool(); } return connectionPoolDatasource.getConnection(); </code></pre> <p>}</p> <pre><code> public static synchronized void initPool() throws SQLException { DBLocation loc = null; try { loc = GTMain.DBConn.get(Util.DB_GURUSTRADE); // C3PO connectionPoolDatasource = new ComboPooledDataSource(); connectionPoolDatasource.setDriverClass(loc.driver); connectionPoolDatasource.setJdbcUrl(loc.url); connectionPoolDatasource.setUser(loc.user); connectionPoolDatasource.setPassword(loc.password); // properties connectionPoolDatasource.setAcquireIncrement(5); connectionPoolDatasource.setMaxIdleTime(3600); connectionPoolDatasource.setMaxIdleTimeExcessConnections(300); connectionPoolDatasource.setMaxPoolSize(100); connectionPoolDatasource.setMinPoolSize(20); connectionPoolDatasource.setNumHelperThreads(6); connectionPoolDatasource.setUnreturnedConnectionTimeout(3600); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>}</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    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