From: | Doug McNaught <doug(at)mcnaught(dot)org> |
---|---|
To: | Joe Tomcat <tomcat(at)mobile(dot)mp> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Solved, and a bug found! Re: JDBC question: Creating new arrays |
Date: | 2002-11-13 14:00:24 |
Message-ID: | m3k7jhr2mf.fsf@varsoon.wireboard.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Joe Tomcat <tomcat(at)mobile(dot)mp> writes:
> On Tue, 2002-11-12 at 17:39, Doug McNaught wrote:
> > Then you probably need to wrap your Java array in an object that
> > implements java.sql.Array so that the JDBC driver can talk to it.
> > Shouldn't be hard.
>
> That still doesn't make it driver-independent, does it?
How not? Implementing java.sql.Array is the JDBC standard way to do
this, though it seems to be a ridiculous amount of work. Whereas:
> Anyway, I found a simple solution that works easily with Postgres: The
> way PreparedStatement.setArray(Array) works is that it actually gets
> translated to PreparedStatement.setString(Array.toString()). The
> Array.toString() method is very simple; it just makes a string that
> looks like '{484,282,945}' (for an int[]) so I just turned my int[] into
> such a string, and called PreparedStatement.setString(). This is a bit
> of a hack, but it seems that there is no db-independent way to do this,
> so I have no other options. If we need to move to some other db, this
> shouldn't be hard to modify as needed.
This is definitely not driver-independent. ;)
> There is one other problem, though: If I have an array with no
> elements, then this operation:
>
> Array array = resultSet.getArray(3);
> Object o = array.getArray();
>
> throws a Bad Integer exception.
This does sound like a bug.
-Doug
From | Date | Subject | |
---|---|---|---|
Next Message | Aurangzeb M. Agha | 2002-11-13 14:01:23 | Re: error: lost syncronization with server |
Previous Message | Csaba Nagy | 2002-11-13 13:58:07 | Re: Upgrade to dual processor machine? |