From: | Szymon Guz <mabewlun(at)gmail(dot)com> |
---|---|
To: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | strange java query behaviour |
Date: | 2011-10-24 20:23:40 |
Message-ID: | CAFjNrYv4MrkbXi-usroCqNiaSyEAzvJ7GjtsEJW2RK7-R=8hiw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I've got a quite strange situation. Below is a simple test
@Test
public void test() throws SQLException {
String query1 = "SELECT * FROM information_schema.schemata WHERE
schema_name = ?";
String query2 = "SELECT * FROM pg_catalog.pg_namespace where nspname
= ?";
check(query1, "1", "public");
check(query2, "2", "public");
}
private void check(final String query, final String info, final String
param) throws SQLException {
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1, param);
ResultSet schemas = stmt.executeQuery();
boolean exists = schemas.next();
System.out.println(info + " : " + exists);
}
The output is:
1 : false
2 : true
When I query the database using psql, both queries return sensible data
(even when I prepare statements in postgres).
I'd like to use information_schema rather than using pg_catalog.
ENV:
Ubuntu 11.10
PostgreSQL 9.0.4 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC)
4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
9.0-801.jdbc4
regards
Szymon
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2011-10-24 20:29:44 | Re: Help with copy (loading TSV file into table as text) |
Previous Message | Alban Hertroys | 2011-10-24 19:36:05 | Re: [pgadmin-support] Help for Migration |