<dependency> <groupId>com.jolbox</groupId> <artifactId>bonecp</artifactId> <version>0.8.0.RELEASE</version> </dependency> BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl("jdbc:mysql://localhost:3306/mydatabase"); config.setUsername("username"); config.setPassword("password"); BoneCP connectionPool = new BoneCP(config); Connection connection = connectionPool.getConnection(); Statement statement = null; ResultSet resultSet = null; try { statement = connection.createStatement(); resultSet = statement.executeQuery("SELECT * FROM my_table"); while (resultSet.next()) { } } catch (SQLException e) { e.printStackTrace(); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if (connection != null) { connection.close(); } } connectionPool.shutdown();


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