Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.beans.PropertyVetoException;
  2. import java.io.IOException;
  3. import java.sql.Connection;
  4. import java.sql.SQLException;
  5.  
  6. import com.mchange.v2.c3p0.ComboPooledDataSource;
  7.  
  8. public class DataSource {
  9.  
  10. private static DataSource datasource;
  11. private ComboPooledDataSource cpds;
  12.  
  13. private DataSource() throws IOException, SQLException, PropertyVetoException {
  14. cpds = new ComboPooledDataSource();
  15. cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver
  16. cpds.setJdbcUrl("jdbc:mysql://192.168.56.31/test");
  17. cpds.setUser("test");
  18. cpds.setPassword("test");
  19.  
  20. // the settings below are optional -- c3p0 can work with defaults
  21. cpds.setMinPoolSize(5);
  22. cpds.setAcquireIncrement(5);
  23. cpds.setMaxPoolSize(20);
  24. cpds.setMaxStatements(180);
  25.  
  26. }
  27.  
  28. public static DataSource getInstance() throws IOException, SQLException, PropertyVetoException {
  29. if (datasource == null) {
  30. datasource = new DataSource();
  31. return datasource;
  32. } else {
  33. return datasource;
  34. }
  35. }
  36.  
  37. public Connection getConnection() throws SQLException {
  38. return this.cpds.getConnection();
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement