modifying the template1 database using a jdbc

From: "SRINIVASARAGHAVAN, RAJESH (HP-Cupertino, ex1)" <rajesh_srinivasaraghavan(at)hp(dot)com>
To: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>, "'pgsql-jdbc(at)postgresql(dot)org'" <pgsql-jdbc(at)postgresql(dot)org>
Cc: "'srajesh(at)cup(dot)hp(dot)com'" <srajesh(at)cup(dot)hp(dot)com>
Subject: modifying the template1 database using a jdbc
Date: 2001-07-19 00:57:18
Message-ID: 877AC5B5F768D511A51600A0C9F4841801DEF787@xcup01.cup.hp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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)

Browse pgsql-jdbc by date

  From Date Subject
Next Message Anders Bengtsson 2001-07-19 14:26:50 Re: [PATCHES] Re: [PATCH] Cleanup of JDBC character encoding
Previous Message Jörg Sommer 2001-07-18 19:17:41 Re: Methode is not yet implemented.