Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.mchange.v2.c3p0.ComboPooledDataSource;
- import javax.sql.DataSource;
- import java.beans.PropertyVetoException;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.SQLException;
- public class MysqlDataSource {
- private static MysqlDataSource dataSource;
- /**
- * The pooled Data source
- */
- private ComboPooledDataSource cpds;
- /**
- * class constructor
- * @throws IOException
- * @throws SQLException
- * @throws PropertyVetoException
- */
- public MysqlDataSource() throws IOException, SQLException, PropertyVetoException {
- cpds = new ComboPooledDataSource();
- cpds.setDriverClass("com.mysql.jdbc.Driver");
- cpds.setJdbcUrl("jdbc:mysql://wownoplis");
- cpds.setUser("root");
- cpds.setPassword("wow ez m9");
- cpds.setMinPoolSize(5);
- cpds.setAcquireIncrement(5);
- cpds.setMaxPoolSize(20);
- cpds.setMaxStatements(180);
- }
- /**
- * Returns the static MysqlDataSource instance
- * @return MysqlDataSource
- * @throws IOException
- * @throws SQLException
- * @throws PropertyVetoException
- */
- public static MysqlDataSource getInstance() throws IOException, SQLException, PropertyVetoException {
- if (dataSource == null) {
- dataSource = new MysqlDataSource();
- return dataSource;
- } else {
- return dataSource;
- }
- }
- /**
- * Returns an java.sql.connection from the connection pool
- * @return Connection
- * @throws SQLException
- */
- public Connection getConnection() throws SQLException {
- return this.cpds.getConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement