PSQLException: The column name <col> was not found in this ResultSet.

From: Michael Fork <mfork00(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: PSQLException: The column name <col> was not found in this ResultSet.
Date: 2010-11-08 13:54:30
Message-ID: 270369.52816.qm@web113412.mail.gq1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

postgresql-9.0-801.jdbc3.jar

PostgreSQL 8.3.7 on amd64-portbld-freebsd7.2, compiled by GCC cc (GCC) 4.2.1
20070719 [FreeBSD]

Caused by: org.postgresql.util.PSQLException: The column name mdn was not found
in this ResultSet.
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2562)

at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:2405)

at
org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:225)

I receive the above error message when accessing the JDBC resultset from
multiple threads. It does not occur consistently, but roughly every 20 or 30
runs and almost immediately upon invocation. Looking
at org/postgresql/jdbc2/AbstractJdbc2ResultSet.java it appears there is a race
condition around building columnNameIndexMap

if (columnNameIndexMap == null) { columnNameIndexMap
= new HashMap(fields.length * 2); // The JDBC spec says when you
have duplicate columns names, // the first one should be returned.
So load the map in // reverse order so the first ones will overwrite
later ones. for (int i = fields.length - 1; i >= 0; i--)
{
columnNameIndexMap.put(fields[i].getColumnLabel().toLowerCase(Locale.US), new
Integer(i + 1)); } }
I cannot confirm this, but I would guess that on thread enters, has the NULL map
and creates the new HashMap. The second thread enters, sees the non-NULL
columnNameIndexMap, and gets to the HashMap.get call prior to the first thread
fully populating the map. If this is the problem, would wrapping the IF block
in a synchronized(this) block fix it?
Thanks.

Michael

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Steven Dahlin 2010-11-09 14:37:36 psqlexception syntax error at or near "$"
Previous Message Thomas Kellerer 2010-11-07 08:43:33 Re: Bug with DatabaseMetaData and temporary tables/schemas