BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl("jdbc:mysql://localhost/test"); config.setUsername("root"); config.setPassword("password"); config.setMinConnectionsPerPartition(5); config.setMaxConnectionsPerPartition(10); BoneCP connectionPool = new BoneCP(config); BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl("jdbc:mysql://localhost/test"); config.setUsername("root"); config.setPassword("password"); config.setConnectionTimeoutInMs(5000); BoneCP connectionPool = new BoneCP(config); Connection connection = connectionPool.getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE id = ?"); statement.setInt(1, 1); ResultSet resultSet = statement.executeQuery(); Connection connection = null; try { connection = connectionPool.getConnection(); } catch (SQLException e) { } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { } } }


上一篇:
下一篇:
切换中文