I am trying to understand whether there is an instruction, like the MySQL's USE
, to choose a database, once created from Java.
I would like at first to access the dbms via the url jdbc:postgresql://localhost:5432/
(without database), so I would insert an instruction to create the db, and so another instruction to use/choose it.
I am building a function that is supposed to connect to dbms, create a database, use it, and finally delete it (as I need temporary data: I tried H2 In Memory but it didn't work in my specific application).
I have been able to realize such a behavior with MySQL, but unluckily I cannot use MySQL; my code for this was:
manager.setJDBCDriver("com.mysql.jdbc.Driver");
manager.setJDBCUsername("root");
manager.setJDBCPassword("mypass");
manager.setJDBCUrl("jdbc:mysql://localhost/");
manager.createConnection();
manager.executeUpdate("CREATE DATABASE " + database);
manager.executeUpdate("USE " + database);
Where I will put the database deletion query in a module calling this latter code.
I would like to do so even with PostgreSQL.