Re: JDBC - Mailing list pgsql-jdbc

From Chuck Davis
Subject Re: JDBC
Date
Msg-id CAHf=Y_Y1Yn559LKWPc9Waw_MEdBTF9Ce2bsbptBmfNZB3HKPKA@mail.gmail.com
Whole thread Raw
In response to JDBC  ("Hanna Tapani" <tapani@kth.se>)
Responses Re: JDBC
Re: JDBC
List pgsql-jdbc
I created a new, empty database and I want to test whether a table
exists or not.  I've googled and thought what I read @ stackoverflow
indicated the following should let me know (I've also seen the same at
other sites):

At instantiation result is set to false.

    private boolean checkEntity()
        // this checks whether this is a new database and tables have
not yet been created and prevent a null pointer exception
        // entities table must exist to use the system
        try {
            stat = connection.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
null, ex);
        }

        try {
            result = stat.execute("select exists (select 1 from
information_schema.tables where table_name = 'entities')");
            System.out.println("the checkEntity returned a result of "
+ result);
        } catch (SQLException ex) {
            Logger.getLogger(ClientConstants.class.getName()).log(Level.SEVERE,
null, ex);
            result = false;
            return result;
        }

        return result;

    }

Even though no objects have been created in the database this result
is always returned true.  The documentation says the
information_schema is unique for each database so this statement
should return false until the table is created....I think.

I've also used this version with the same result:
            result = stat.execute("SELECT EXISTS (SELECT 1 FROM
information_schema.tables WHERE table_schema = 'jpl' AND table_name =
'entities')");

The only thing I can think of is that the information_schema is
actually for the cluster.  I have other databases in the cluster that
do have an entities table.

Any direction will be appreciated.


pgsql-jdbc by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: [pgjdbc/pgjdbc] a69996: chore: remove ubenchmark from packaging/rpmas wel...
Next
From: Tom Lane
Date:
Subject: Re: JDBC