Guest User

Untitled

a guest
Sep 10th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. // Create a new datasource
  2. dataSource = PGSimpleDataSource()
  3. dataSource.setURL("jdbc:postgresql://mydbserver:5432/admin")
  4. dataSource.setUser("test")
  5. dataSource.setPassword("testing")
  6.  
  7. // get connection to admin db and create a new database named 'mynewdb'
  8. connection = dataSource.getConnection()
  9. cs = connection.createStatement()
  10. cs.executeUpdate("create database mynewdb")
  11. cs.close()
  12. connection.close()
  13.  
  14. // switch to the newly created database using the **same datasource**
  15. dataSource.setDatabaseName(mynewdb)
  16. connection_to_new_db = dataSource.getConnection()
  17. ps = connection_to_new_db.preparedStatement()
  18.  
  19. ....start doing transactions on the newly created database...
  20. ....start doing transactions on the newly created database...
Add Comment
Please, Sign In to add comment