Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. import com.mchange.v2.c3p0.ComboPooledDataSource;
  2.  
  3. import javax.sql.DataSource;
  4. import java.beans.PropertyVetoException;
  5. import java.io.IOException;
  6. import java.sql.Connection;
  7. import java.sql.SQLException;
  8.  
  9.  
  10. public class MysqlDataSource {
  11.  
  12.  
  13.     private static MysqlDataSource dataSource;
  14.  
  15.     /**
  16.      * The pooled Data source
  17.      */
  18.     private ComboPooledDataSource cpds;
  19.  
  20.     /**
  21.      * class constructor
  22.      * @throws IOException
  23.      * @throws SQLException
  24.      * @throws PropertyVetoException
  25.      */
  26.     public MysqlDataSource() throws IOException, SQLException, PropertyVetoException {
  27.         cpds = new ComboPooledDataSource();
  28.         cpds.setDriverClass("com.mysql.jdbc.Driver");
  29.         cpds.setJdbcUrl("jdbc:mysql://wownoplis");
  30.         cpds.setUser("root");
  31.         cpds.setPassword("wow ez m9");
  32.  
  33.         cpds.setMinPoolSize(5);
  34.         cpds.setAcquireIncrement(5);
  35.         cpds.setMaxPoolSize(20);
  36.         cpds.setMaxStatements(180);
  37.     }
  38.  
  39.  
  40.     /**
  41.      * Returns the static MysqlDataSource instance
  42.      * @return MysqlDataSource
  43.      * @throws IOException
  44.      * @throws SQLException
  45.      * @throws PropertyVetoException
  46.      */
  47.     public static MysqlDataSource getInstance() throws IOException, SQLException, PropertyVetoException {
  48.         if (dataSource == null) {
  49.             dataSource = new MysqlDataSource();
  50.             return dataSource;
  51.         } else {
  52.             return dataSource;
  53.         }
  54.     }
  55.  
  56.     /**
  57.      * Returns an java.sql.connection from the connection pool
  58.      * @return Connection
  59.      * @throws SQLException
  60.      */
  61.     public Connection getConnection() throws SQLException {
  62.         return this.cpds.getConnection();
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement