metadata.getColumns() using Apache Tomcat / jndi

From: Thomas Strunz <beginner_(at)hotmail(dot)de>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: metadata.getColumns() using Apache Tomcat / jndi
Date: 2011-09-30 06:13:47
Message-ID: DUB114-W45402DA072DA2469848E6FEEF70@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc


Hi all,

issue affects 9.1-901.jdbc4 and 9.0-801.jdbc4 driver.

i have following java code:

<pre>
Connection conn = dataSource.getConnection();
DatabaseMetaData metaData = conn.getMetaData();
this.databaseProductName = metaData.getDatabaseProductName();
ResultSet rsColumns = metaData.getColumns(
null, null, tableName, null);
while (rsColumns.next()) {
//..do work
}
rsColumns.close();
conn.close();
</pre>

This works fine when initializing the PostgreSQL DataSoource manually as in:
<pre>
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setDatabaseName(postgresqlDatabaseName);
dataSource.setServerName(postgresqlHost);
dataSource.setUser(postgresqlUser);
dataSource.setPassword(postgresqlPW);
return dataSource;
</pre>

If I want to get the datasource from jndi / tomcat as in:

<Resource name="jdbc/Zinc"
auth="Container"
type="javax.sql.DataSource"
username="yyyyyy"
password="xxxxxx"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql:Zinc"
maxActive="20"
maxIdle="4"/>

the result set returned by metaData.getColumns(null, null, tableName, null) is always empty.

However if I use MySQL, SQL Server or HSQLDB the code also works in tomcat eg.

<Resource name="jdbc/Zinc"
auth="Container"
type="javax.sql.DataSource"
username="sa"
password=""
driverClassName="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:hsql://localhost/ZincDB"
maxActive="20"
maxIdle="4"/>

works perfectly fine and metaData.getColumns returns exactly what I would expect.

My table name only contains letters and is all lower case (postgresql jdbc is IMHO a bit quirky since table and field names seem to be partially case-sensitive).

Any ideas? Bug? the problem does seem to be a postgresql issue (and not tomcat) because code works fine for other JDBC Drivers.

Thanks for your help.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2011-09-30 10:07:00 Re: metadata.getColumns() using Apache Tomcat / jndi
Previous Message Mikko Tiihonen 2011-09-29 23:12:16 Re: Collection of small fixes to binary transfer code and unit tests