modifying the template1 database using a jdbc - Mailing list pgsql-jdbc

From SRINIVASARAGHAVAN,RAJESH (HP-Cupertino,ex1)
Subject modifying the template1 database using a jdbc
Date
Msg-id 877AC5B5F768D511A51600A0C9F4841801DEF787@xcup01.cup.hp.com
Whole thread Raw
List 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)

pgsql-jdbc by date:

Previous
From: Jörg Sommer
Date:
Subject: Re: Methode is not yet implemented.
Next
From: Bruce Momjian
Date:
Subject: Re: Connection.setCatalog()