SQLException: Invalid precision value. Cannot be less than zero

From: "Nebojsa Vasiljevic" <nebojsa(at)sw4i(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: SQLException: Invalid precision value. Cannot be less than zero
Date: 2005-02-09 22:35:54
Message-ID: 000901c50ef7$b787f9e0$ad00a8c0@mediacenter.org.yu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

The exception occures in populate() method:

CachedRowSetImpl rowSet = new CachedRowSetImpl();
r=as.executeQuery("select * from an_tnratio");
rowSet.populate(r);

Table definition is:

-- Table: an_tnratio

-- DROP TABLE an_tnratio;

CREATE TABLE an_tnratio
(
ssize text,
edulh text,
tnratio numeric
)
WITH OIDS;
ALTER TABLE an_tnratio OWNER TO elan;

Stack trace:

java.sql.SQLException: Invalid column display size. Cannot be less than zero
at
javax.sql.rowset.RowSetMetaDataImpl.setColumnDisplaySize(RowSetMetaDataImpl.java:267)
at
com.sun.rowset.CachedRowSetImpl.initMetaData(CachedRowSetImpl.java:679)
at
com.sun.rowset.CachedRowSetImpl.populate(CachedRowSetImpl.java:597)
at com.sw4i.elan.engine.Table$1.doo(Table.java:51)
...

Driver version: 8.0-310 (postgresql-8.0-310.jdbc3.jar)
Sun JDK version: 1.5.0_01-b08
Database PosgreSQL 8.0.0 on i686-pc-mingw32, compiled by GCC gcc.exe(GCC)
3.4.2 (mingw-special)

The problem is "return -1" statement in
org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getPrecision():

case Types.NUMERIC:
Field f = getField(column);
if (f != null)
{
// no specified precision or scale
if (f.getMod() == -1)
{
return -1;
}
return ((0xFFFF0000)&f.getMod()) >> 16;
}
else
{
return 0;
}

After I have pached getPrecision(), getScale() and getColumnDisplaySize() to
return 0 instead of negative value, my program works fine. I haven't find in
JDBC specification what those methods should return for
"unknown/unspecified", but other drivers (like JdbcOdbcDriver) returns 0.

Nebojsa Vasiljevic

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2005-02-10 07:58:45 Re: Crystal Reports / PostgreSQL
Previous Message Markus Schaber 2005-02-09 17:46:59 Re: context classloader