Last active
August 27, 2018 20:50
-
-
Save ColbyLeclerc/79fa3b211d974573302e896a6db974c6 to your computer and use it in GitHub Desktop.
DBCP example found at https://github.com/ColbyLeclerc/blog-connection-pools/blob/master/src/main/java/database/DBCPDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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