Skip to content

Instantly share code, notes, and snippets.

@ColbyLeclerc
Last active August 27, 2018 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColbyLeclerc/79fa3b211d974573302e896a6db974c6 to your computer and use it in GitHub Desktop.
Save ColbyLeclerc/79fa3b211d974573302e896a6db974c6 to your computer and use it in GitHub Desktop.
//See https://github.com/ColbyLeclerc/blog-connection-pools/blob/master/src/main/java/database/DBCPDatabase.java
package database;
import org.apache.commons.dbcp2.BasicDataSource;
import java.sql.SQLException;
public class DBCPDatabase {
private static BasicDataSource dataSource;
//Insert log4j statement
public static BasicDataSource getDataSource() {
if (dataSource == null) {
BasicDataSource ds = new BasicDataSource();
ds.setUrl("jdbc:sqlserver://localhost;databaseName=testdba");
ds.setUsername("testdb");
ds.setPassword("W91gLUJWfRS3sg37");
ds.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
ds.setInitialSize(3);
ds.setMaxTotal(25);
ds.setMinIdle(0);
ds.setMaxIdle(8);
ds.setMaxOpenPreparedStatements(100);
dataSource = ds;
}
return dataSource;
}
public static void shutdown() {
if (dataSource != null){
try {
dataSource.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment