params.put( PORT.key, port );
params.put( USER.key, username );
params.put( PASSWD.key, password );
params.put( DATABASE.key, "template1");
BasicDataSource source = PostgisServiceExtension2.getFactory().createDataSource(params );
Connection connection = source.getConnection();
try {
Statement statement = connection.createStatement();
if (statement.execute("SELECT datname FROM pg_database")) {
ResultSet resultSet = statement.getResultSet();
while (resultSet.next()) {
databaseNames.add(resultSet.getString("datname"));
}
}
statement.close();
} finally {
if( connection != null ){
connection.close();
}
if( source != null ){
source.close();
}
}
}
catch (SQLException e) {
checkSqlException(e);