I want to create a database PostgreSQL using Java but I got an error message.
Here is my code :
try {
Connection c=null;
Statement stmt=null;
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/",
"postgres", "Admin@2014");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "CREATE DATABASE db OWNER postgres TABLESPACE numerique; ";
stmt.executeUpdate(sql);
stmt.close();
c.commit();
c.close();
} catch (Exception ee) {
System.err.println( ee.getClass().getName()+": "+ ee.getMessage() );
System.exit(0);
}
Here is the error message that I got :
org.postgresql.util.PSQLException: ERREUR: CREATE DATABASE ne peut pas être exécuté dans un bloc de transaction
Thank you for your help.