Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void initSource() {
- try {
- // load the underlying driver
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException ex) {
- System.err.println("Error loading Postgres driver: " + ex.getMessage());
- ex.printStackTrace();
- System.exit(1);
- }
- // Build the DSN: jdbc:postgresql://host:port/database
- StringBuilder buf = new StringBuilder();
- buf.append("jdbc:postgresql://").append(Configatron.get().getProperty("db.host")).append(":");
- buf.append(Configatron.get().getProperty("db.port")).append("/");
- buf.append(Configatron.get().getProperty("db.name"));
- log.info("DSN: " + buf.toString());
- Properties props = new Properties();
- props.setProperty("user", Configatron.get().getProperty("db.user"));
- props.setProperty("password", Configatron.get().getProperty("db.password"));
- props.setProperty("initialSize", "5");
- props.setProperty("maxActive", Configatron.get().getProperty("db.maxConnections"));
- connectionFactory = new DriverManagerConnectionFactory(buf.toString(), props);
- connectionPool = new GenericObjectPool(null);
- poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
- dataSource = new PoolingDataSource(connectionPool);
- } catch (Exception ex) {
- // handle the error
- System.err.println("Got error initializing data source: " + ex.getMessage());
- System.exit(1);
- }
- }
Add Comment
Please, Sign In to add comment