Re: metadata.getColumns() using Apache Tomcat / jndi

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Thomas Strunz <beginner_(at)hotmail(dot)de>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: metadata.getColumns() using Apache Tomcat / jndi
Date: 2011-09-30 10:07:00
Message-ID: CADK3HHLXnVhBL6TmR8nZ+jTpA2WCsi=do2rtg260EBz8Se2Y1A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Thomas,

Any chance you can see what is in the server logs ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On Fri, Sep 30, 2011 at 2:13 AM, Thomas Strunz <beginner_(at)hotmail(dot)de> wrote:
> 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.
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2011-09-30 12:08:32 Re: setBlob(InputStream) not supported?
Previous Message Thomas Strunz 2011-09-30 06:13:47 metadata.getColumns() using Apache Tomcat / jndi