Guest User

Untitled

a guest
Aug 3rd, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1.  
  2. private void initSource() {
  3. try {
  4.  
  5. // load the underlying driver
  6. try {
  7. Class.forName("org.postgresql.Driver");
  8. } catch (ClassNotFoundException ex) {
  9. System.err.println("Error loading Postgres driver: " + ex.getMessage());
  10. ex.printStackTrace();
  11. System.exit(1);
  12. }
  13. // Build the DSN: jdbc:postgresql://host:port/database
  14. StringBuilder buf = new StringBuilder();
  15. buf.append("jdbc:postgresql://").append(Configatron.get().getProperty("db.host")).append(":");
  16. buf.append(Configatron.get().getProperty("db.port")).append("/");
  17. buf.append(Configatron.get().getProperty("db.name"));
  18. log.info("DSN: " + buf.toString());
  19.  
  20. Properties props = new Properties();
  21. props.setProperty("user", Configatron.get().getProperty("db.user"));
  22. props.setProperty("password", Configatron.get().getProperty("db.password"));
  23. props.setProperty("initialSize", "5");
  24. props.setProperty("maxActive", Configatron.get().getProperty("db.maxConnections"));
  25.  
  26. connectionFactory = new DriverManagerConnectionFactory(buf.toString(), props);
  27. connectionPool = new GenericObjectPool(null);
  28. poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
  29.  
  30. dataSource = new PoolingDataSource(connectionPool);
  31.  
  32. } catch (Exception ex) {
  33. // handle the error
  34. System.err.println("Got error initializing data source: " + ex.getMessage());
  35. System.exit(1);
  36. }
  37. }
Add Comment
Please, Sign In to add comment