Re: JDBC
От
Chuck Davis
Тема
Re: JDBC
Дата
Msg-id
CAHf=Y_Y1Yn559LKWPc9Waw_MEdBTF9Ce2bsbptBmfNZB3HKPKA@mail.gmail.com
Список
Дерево обсуждения
Re: JDBC Chuck Davis <cjgunzel@gmail.com>
Re: JDBC Tom Lane <tgl@sss.pgh.pa.us>
Re: JDBC Chuck Davis <cjgunzel@gmail.com>
Re: JDBC "David G. Johnston" <david.g.johnston@gmail.com>
Re: JDBC Chuck Davis <cjgunzel@gmail.com>
Re: JDBC Dave Cramer <pg@fastcrypt.com>
Re: JDBC Chuck Davis <cjgunzel@gmail.com>
Re: JDBC "David G. Johnston" <david.g.johnston@gmail.com>
Re: JDBC Chuck Davis <cjgunzel@gmail.com>
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 по дате отправления
От: Vladimir Sitnikov
Дата: