Re: JDBC

From: Chuck Davis <cjgunzel(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: JDBC
Date: 2018-06-10 20:24:55
Message-ID: CAHf=Y_Y1Yn559LKWPc9Waw_MEdBTF9Ce2bsbptBmfNZB3HKPKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

  • Re: JDBC at 2018-06-10 20:40:46 from Tom Lane
  • Re: JDBC at 2018-06-10 20:44:25 from David G. Johnston

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2018-06-10 20:40:46 Re: JDBC
Previous Message Vladimir Sitnikov 2018-06-10 09:17:06 [pgjdbc/pgjdbc] a69996: chore: remove ubenchmark from packaging/rpm as wel...