Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a new datasource
- dataSource = PGSimpleDataSource()
- dataSource.setURL("jdbc:postgresql://mydbserver:5432/admin")
- dataSource.setUser("test")
- dataSource.setPassword("testing")
- // get connection to admin db and create a new database named 'mynewdb'
- connection = dataSource.getConnection()
- cs = connection.createStatement()
- cs.executeUpdate("create database mynewdb")
- cs.close()
- connection.close()
- // switch to the newly created database using the **same datasource**
- dataSource.setDatabaseName(mynewdb)
- connection_to_new_db = dataSource.getConnection()
- ps = connection_to_new_db.preparedStatement()
- ....start doing transactions on the newly created database...
- ....start doing transactions on the newly created database...
Add Comment
Please, Sign In to add comment