public class ExampleDataSource {
public static void main(String[] args) {
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
e.printStackTrace();
}
BoneCPDataSource dataSource=new BoneCPDataSource();
dataSource.setUsername("root");
dataSource.setPassword("root");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/stopsix_two_phase");
dataSource.setMaxConnectionsPerPartition(10);
dataSource.setMinConnectionsPerPartition(5);
dataSource.setIdleMaxAge(240);
dataSource.setAcquireIncrement(5);
dataSource.setReleaseHelperThreads(3);
dataSource.setIdleConnectionTestPeriod(60);
dataSource.setPartitionCount(3);
dataSource.setAcquireIncrement(5);
dataSource.setStatementsCacheSize(100);
try {
connection=dataSource.getConnection();
if (connection != null){
System.out.println("Connection successful!");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(" select 1+1 numb "); // do something with the connection.
while(rs.next()){
System.out.println(rs.getString("numb")); // should print out "1"'
System.out.println(rs.getInt("numb")); // should print out 1
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
jar包:
bonecp-0.7.1.RELEASE.jar,
guava-14.0.1.jar,
log4j-1.2.16.jar,
mysql-connector-java-5.1.33.jar,
slf4j-api-1.6.1.jar,
slf4j-log4j12-1.6.1.jar