hi all,
I am trying to create a database in postgres using a jdbc call. The same SQL
query works in command line using psql.
I am using 7.1.2 postgresql database and the jdbc jar that comes with it.
I get the following error. Do you know what the problem is
java.sql.SQLException: ERROR: CREATE DATABASE: source database "template1"
is being accessed by other users
I have been able to create an user using a similar jdbc call. Is there any
locking issues that I am missing or is a bug? The problem happens only when
the table is template1! That makes me conclude that it could be a postgres
issue and not a jdbc issue.
The relevant lines of code are
for (int i = 0; i < 10; i++) {
try {
String tmpdbURL =
"jdbc:postgresql://hostname.domainname.com/template1";
Class.forName("org.postgresql.Driver");
Connection tmpCon = DriverManager.getConnection(tmpdbURL,
"test", "test");
Statement tmpStmt = tmpCon.createStatement();
tmpStmt.executeUpdate("CREATE DATABASE testuser31" + i +
";");
tmpStmt.close();
tmpCon.close();
} catch(Exception e) {
e.printStackTrace();
System.out.println("TEST 0 failed");
}
try {
Thread.sleep(150000);
} catch (Exception e) {
}
thanks
rajesh
(reply to srajesh (at) cup.hp.com)