pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
SQLException: Invalid precision value. Cannot be less than zero
7+ messages / 4 participants
[nested] [flat]

* SQLException: Invalid precision value. Cannot be less than zero
@ 2005-02-09 22:35 Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 08:12 ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Nebojsa Vasiljevic @ 2005-02-09 22:35 UTC (permalink / raw)
  To: 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




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQLException: Invalid precision value. Cannot be less
  2005-02-09 22:35 SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
@ 2005-02-10 08:12 ` Kris Jurka <books@ejurka.com>
  2005-02-10 09:50   ` Re: SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 10:15   ` Re: SQLException: Invalid precision value. Cannot be less than Amit Handa <Amit.Handa@Sun.COM>
  0 siblings, 2 replies; 7+ messages in thread

From: Kris Jurka @ 2005-02-10 08:12 UTC (permalink / raw)
  To: Nebojsa Vasiljevic <nebojsa@sw4i.com>; +Cc: pgsql-jdbc; amit.handa@sun.com; kmacclay@vantage.com; bmaguire@vantage.com



On Wed, 9 Feb 2005, Nebojsa Vasiljevic wrote:

> [CachedRowSet doesn't like -1 precision values for numeric]

This has been discussed, partially offlist, with Sun in the context of 
getColumnDisplaySize returning -1 for text and varchar with no length 
attribute fields.  I've been waiting for a suggestion from Sun on what 
value to use, or if they will alter their code to remove this check.

Your suggestion of using 0 passes their check, but still isn't legal:

jurka=# create table nt (a numeric(0,0));
ERROR:  NUMERIC precision 0 must be between 1 and 1000

The -1 value is intended to indicate we don't know or unlimited or 
similar and I don't particularly like it, but I've yet to hear a better 
suggestion.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQLException: Invalid precision value. Cannot be less than zero
  2005-02-09 22:35 SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 08:12 ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
@ 2005-02-10 09:50   ` Nebojsa Vasiljevic <nebojsa@sw4i.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Nebojsa Vasiljevic @ 2005-02-10 09:50 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc; amit.handa@sun.com; kmacclay@vantage.com; bmaguire@vantage.com


> This has been discussed, partially offlist, with Sun in the context of
> getColumnDisplaySize returning -1 for text and varchar with no length
> attribute fields.  I've been waiting for a suggestion from Sun on what
> value to use, or if they will alter their code to remove this check.

javax.sql.rowset.RowSetMetaDataImpl class is part of Sun JDK 1.5.
I don't like Sun forces  nonegative values in 
javax.sql.rowset.RowSetMetaDataImpl,
but we can't change it. Sun will not change the JDK to make PosgreSQL driver
work.

Don't wait for Sun's suggestion, just look how other drivers works.


>
> Your suggestion of using 0 passes their check, but still isn't legal:
>
> jurka=# create table nt (a numeric(0,0));
> ERROR:  NUMERIC precision 0 must be between 1 and 1000

"create table nt (a numeric(0,0))" is as illegal as "create table nt (a 
numeric(-1,-1))".
Precision  0 stands for "create table nt (a numeric)".


Nebojsa




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQLException: Invalid precision value. Cannot be less than
  2005-02-09 22:35 SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 08:12 ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
@ 2005-02-10 10:15   ` Amit Handa <Amit.Handa@Sun.COM>
  2005-02-10 10:49     ` Re: SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 15:24     ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
  1 sibling, 2 replies; 7+ messages in thread

From: Amit Handa @ 2005-02-10 10:15 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Nebojsa Vasiljevic <nebojsa@sw4i.com>; pgsql-jdbc; kmacclay@vantage.com; bmaguire@vantage.com; Amit Handa <Amit.Handa@Sun.COM>

That's right we *can't change the spec*.

But hold on guys, I can put a try catch block for this and prevent
the SQLException from being thrown in the implementation,
wherever it is being called in from *other classes*.
And hence we can go on.

But yes I can't change the spec class from doing that.
It's(return -1 for variable length data) is used by various JDBC drivers 
that way.

Does that help ?

Also, Can you give me the stack trace of the exception ?
I just want to confirm the try catch block I put is at the right place
(i.e. exception will be caught in CachedRowSetImpl.java),
and works with you guys.

Further I am going to file a bug with our bug tracking system
and get some feedback internally, so that I keep things black and white.
You can view it over the web later as well.

thanks,
Amit Handa,
Sun Microsystems Inc.

PS: Kevin seems to have vanished ;)
I was trying to help him with this and some other problems but never 
heard back,
though I am also slow at times to get back to him because of other 
commitments.


Kris Jurka wrote:

>On Wed, 9 Feb 2005, Nebojsa Vasiljevic wrote:
>
>  
>
>>[CachedRowSet doesn't like -1 precision values for numeric]
>>    
>>
>
>This has been discussed, partially offlist, with Sun in the context of 
>getColumnDisplaySize returning -1 for text and varchar with no length 
>attribute fields.  I've been waiting for a suggestion from Sun on what 
>value to use, or if they will alter their code to remove this check.
>
>Your suggestion of using 0 passes their check, but still isn't legal:
>
>jurka=# create table nt (a numeric(0,0));
>ERROR:  NUMERIC precision 0 must be between 1 and 1000
>
>The -1 value is intended to indicate we don't know or unlimited or 
>similar and I don't particularly like it, but I've yet to hear a better 
>suggestion.
>
>Kris Jurka
>
>  
>




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQLException: Invalid precision value. Cannot be less than zero
  2005-02-09 22:35 SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 08:12 ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
  2005-02-10 10:15   ` Re: SQLException: Invalid precision value. Cannot be less than Amit Handa <Amit.Handa@Sun.COM>
@ 2005-02-10 10:49     ` Nebojsa Vasiljevic <nebojsa@sw4i.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Nebojsa Vasiljevic @ 2005-02-10 10:49 UTC (permalink / raw)
  To: Amit Handa <Amit.Handa@Sun.COM>; Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc; kmacclay@vantage.com; bmaguire@vantage.com; Amit Handa <Amit.Handa@Sun.COM>



> That's right we *can't change the spec*.
>
> But hold on guys, I can put a try catch block for this and prevent
> the SQLException from being thrown in the implementation,
> wherever it is being called in from *other classes*.
> And hence we can go on.
>
> But yes I can't change the spec class from doing that.
> It's(return -1 for variable length data) is used by various JDBC drivers 
> that way.
>
> Does that help ?

Method

javax.sql.rowset.RowSetMetaDataImpl.setColumnDisplaySize()

throws exception after it is called from:

com.sun.rowset.CachedRowSetImpl.initMetaData(CachedRowSetImpl.java:679)

If you catch exception in CachedRowSetImpl.java, you have to decide what 
value
to put in columnDisplaySize property. Possible answer is:

If columnDisplaySize, precision or scale property of ResultSetMetaData is -1 
then appropriate property of RowSetMetaDataImpl will be 0.

(and you don't need try/catcher to do that)

If various JDBC drivers use -1, this may be reasonable solution.


Nebojsa 




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQLException: Invalid precision value. Cannot be less
  2005-02-09 22:35 SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
  2005-02-10 08:12 ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
  2005-02-10 10:15   ` Re: SQLException: Invalid precision value. Cannot be less than Amit Handa <Amit.Handa@Sun.COM>
@ 2005-02-10 15:24     ` Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Kris Jurka @ 2005-02-10 15:24 UTC (permalink / raw)
  To: Amit Handa <Amit.Handa@Sun.COM>; +Cc: Nebojsa Vasiljevic <nebojsa@sw4i.com>; pgsql-jdbc; kmacclay@vantage.com; bmaguire@vantage.com



On Thu, 10 Feb 2005, Amit Handa wrote:

> Also, Can you give me the stack trace of the exception ?
> I just want to confirm the try catch block I put is at the right place
> (i.e. exception will be caught in CachedRowSetImpl.java),
> and works with you guys.

See the original message here:

http://archives.postgresql.org/pgsql-jdbc/2005-02/msg00049.php

> Further I am going to file a bug with our bug tracking system
> and get some feedback internally, so that I keep things black and white.
> You can view it over the web later as well.

Great.

> I was trying to help him with this and some other problems but never
> heard back, though I am also slow at times to get back to him because of
> other commitments.
> 

Well please raise any other problems you have here on this list and we'll 
try and help you out.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: SQLException: Invalid precision value. Cannot be less than zero
@ 2005-02-10 17:28 Kevin MacClay <kmacclay@vantage.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Kevin MacClay @ 2005-02-10 17:28 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; Amit Handa <Amit.Handa@Sun.COM>; +Cc: Nebojsa Vasiljevic <nebojsa@sw4i.com>; pgsql-jdbc; Brian Maguire <bmaguire@vantage.com>

I'm still here.  At this point, I have found a total of three problems
using the CachedRowSet with Postgres.  The first was the issue with the
"Invalid column display size" exception.  The other two seemed less
related to the JDBC driver, but I will post more detailed descriptions
to everyone outside of the mailing list.

Kevin MacClay

-----Original Message-----
From: Kris Jurka [mailto:books@ejurka.com] 
Sent: Thursday, February 10, 2005 10:25 AM
To: Amit Handa
Cc: Nebojsa Vasiljevic; pgsql-jdbc@postgresql.org; Kevin MacClay; Brian
Maguire
Subject: Re: [JDBC] SQLException: Invalid precision value. Cannot be
less than zero

On Thu, 10 Feb 2005, Amit Handa wrote:

> Also, Can you give me the stack trace of the exception ?
> I just want to confirm the try catch block I put is at the right place

> (i.e. exception will be caught in CachedRowSetImpl.java), and works 
> with you guys.

See the original message here:

http://archives.postgresql.org/pgsql-jdbc/2005-02/msg00049.php

> Further I am going to file a bug with our bug tracking system and get 
> some feedback internally, so that I keep things black and white. You 
> can view it over the web later as well.

Great.

> I was trying to help him with this and some other problems but never 
> heard back, though I am also slow at times to get back to him because 
> of other commitments.
> 

Well please raise any other problems you have here on this list and
we'll 
try and help you out.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2005-02-10 17:28 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09 22:35 SQLException: Invalid precision value. Cannot be less than zero Nebojsa Vasiljevic <nebojsa@sw4i.com>
2005-02-10 08:12 ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
2005-02-10 09:50   ` Nebojsa Vasiljevic <nebojsa@sw4i.com>
2005-02-10 10:15   ` Re: SQLException: Invalid precision value. Cannot be less than Amit Handa <Amit.Handa@Sun.COM>
2005-02-10 10:49     ` Nebojsa Vasiljevic <nebojsa@sw4i.com>
2005-02-10 15:24     ` Re: SQLException: Invalid precision value. Cannot be less Kris Jurka <books@ejurka.com>
2005-02-10 17:28 Re: SQLException: Invalid precision value. Cannot be less than zero Kevin MacClay <kmacclay@vantage.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox