Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 95067B5DBC7 for ; Fri, 30 Sep 2011 12:20:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 28381-06 for ; Fri, 30 Sep 2011 15:20:23 +0000 (UTC) X-Greylist: delayed 00:09:08.654107 by SQLgrey-1.8.0-rc2 Received: from outbound.vnet-inc.com (outbound.vnet-inc.com [216.146.104.103]) by mail.postgresql.org (Postfix) with ESMTP id 52A06B5DBC1 for ; Fri, 30 Sep 2011 12:20:23 -0300 (ADT) Received: from [192.168.157.132] (unknown [76.75.27.41]) by outbound.vnet-inc.com (Postfix) with ESMTP id E70095A39; Fri, 30 Sep 2011 09:11:13 -0600 (MDT) Message-ID: <4E85DB26.1050802@ttc-cmc.net> Date: Fri, 30 Sep 2011 09:07:18 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: Thomas Strunz , PostgreSQL JDBC Subject: Re: metadata.getColumns() using Apache Tomcat / jndi References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/134 X-Sequence-Number: 22252 Thomas Strunz wrote: > Hi all, > > issue affects 9.1-901.jdbc4 and 9.0-801.jdbc4 driver. > > i have following java code: > >
> 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();
> 
> > This works fine when initializing the PostgreSQL DataSoource manually as in: > ~ > ~ > ~ > 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. > 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. According to the Java 6 API for getColumns(): Parameters: catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search schemaPattern - a schema name pattern; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search tableNamePattern - a table name pattern; must match the table name as it is stored in the database columnNamePattern - a column name pattern; must match the column name as it is stored in the database You will notice that the columnNamePattern: must match the column name....... If you send NULL then you have not specified a column name so that the JDBC appears to not return one, NULL. However right or wrong this is this is exactly what is happening with the PostgreSQL JDBC. Class Abstractjdbc2DatabaseMetaData: java.sql.ResultSet getColumns(int jdbcVersion, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) ~ ~ ~ if (columnNamePattern != null && !"".equals(columnNamePattern)) { sql += " AND attname LIKE " + escapeQuotes(columnNamePattern); } This is the only place that the columnNamePattern name is specified. I have not checked beyound this, but the general sql query is not then picking up all the column names as you might expect to be returned. danap