I have created a set of SQL queries that modify a database, and now I want to test them.
How can I create a local and temporary PostgreSQL database to test my queries. I'm working in Java.
PostgreSQL JDBC Driver allows Java programs to connect to a PostgreSQL database using standard, database independent Java code. Is an open source JDBC driver written in Pure Java (Type 4), and communicates in the PostgreSQL native network protocol.
To create the database tables in Java DB, the database server included with Application Server, you need to create the database connection and execute the SQL commands in tut-install /examples/common/sql/javadb/tutorial.
You CAN create and drop PostgreSQL db's via Java using the Statement object.
Example:
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/", "username", "password");
Statement statement = c.createStatement();
statement.executeUpdate("DROP DATABASE mydb");
See the following link for a good starting point:
http://www.jvmhost.com/articles/create-drop-databases-dynamically-java-jsp-code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With