hi, i want to make connection pool for postgresql database, currently i am using normal connection like that:
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost/dbname", "user",
"1234");
Statement select = connection.createStatement();
ResultSet result = select.executeQuery("SELECT * FROM table");
System.out.println("The results of the query:");
ResultSetMetaData metadata = result.getMetaData();
System.out.println("There are " + metadata.getColumnCount() + " columns");
connection.close();
it works perfect.
how can i adopted it to using a pool connection? i mean, i have read doc file about conection pools in postgres:
http://jdbc.postgresql.org/documentation/publicapi/org/postgresql/ds/PGPoolingDataSource.htm
http://www.postgresql.org/docs/7.3/interactive/jdbc-datasource.html
and its all says to use some kind of:
Jdbc3PoolingDataSource source = new Jdbc3PoolingDataSource();
//or PGPoolingDataSource source =new PGPoolingDataSource();
source.setDataSourceName("A Data Source");
source.setServerName("localhost");
source.setDatabaseName("test");
source.setUser("testuser");
source.setPassword("testpassword");
source.setMaxConnections(10);
Connection con = null;
try {
con = source.getConnection();
// use connection
} catch(SQLException e) {
// log error
} finally {
if(con != null) {
try {con.close();}catch(SQLException e) {}
}
}
but i cant make it works. when i am trying to use PGPoolingDataSource method (like source.setDataSourceName("A Data Source"); ) i get an error with synax.
(i still can initialize PGPoolingDataSource variable, but i can do anything with that)
i am using eclipse(3.2) ide, postgresql-8.3dev-600.jdbc3.jar driver, java 1.5, and postgresql 8.2 database.
what i am doing wrong? or how to do this correct?
any ideas/samples how to use connection pooling with postqresql?