Hello 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);
}
and 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 you're help