Re: examples of SQL Arrays and jdbc?

From: Richard Welty <rwelty(at)averillpark(dot)net>
To: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: examples of SQL Arrays and jdbc?
Date: 2003-02-07 16:00:45
Message-ID: E18hAvl-00032t-00@skipper.averillpark.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 06 Feb 2003 20:27:19 -0500 Dave Cramer <Dave(at)micro-automation(dot)net> wrote:

> Yes, in general any postgres data type can be set/get using
> setString/getString
>
> This may change in the future, it is really an artifact of the wire
> protocol
>
> Be warned!

taking this advice to heart, i switched my code to write jdbc int arrays
from using strings, per eric's posting, to using Integer arrays, saving
them with setObject, per page 266-267 of the sun jdbc book (second
edition). their example shows an array of strings:

String [] departments = {"accounting", "personal", "marketing"};
PreparedStatement pstmt = con.prepareStatement(
"UPDATE AJAX_LTD SET DEPTS = ? WHERE ID = 0045");
pstmt.setObject( 1, departments);

my code differs in that the object is an Integer [],

Debug.println( "starting arrays, field_index: " + field_index);
statement.setObject( ++field_index,
intArrayToInteger( target_percentages));
Debug.println( "first array done, field_index: " + field_index);

where intArrayToInteger appears to work correctly, and is as follows:

public static Integer [] intArrayToInteger( int [] ints){
Integer [] IntArray = new Integer [ints.length];

for( int i = 0; i < ints.length; i++){
IntArray[i] = new Integer( ints[i]);
}
return IntArray;
}

i'm getting the following error:

starting arrays, field_index: 7
SQLException: The table for [Ljava.lang.Integer;
is not in the database. Contact the DBA, as the
database is in an inconsistent state.

i'd previously seen this when i mistakenly tried to pass int [] arrays to
setObject. am i missing something here? perhaps some Objects work and not
others?

environment (which i inadvertantly left out of my note earlier today on my
problems with set methods on my UPDATE statement):

RedHat 7.3
postgresql installed from rpm, 7.2.1-5
pgjdbc2.jar driver from website late october of last year
jdk 1.4.1_01

thanks in advance,
richard
--
Richard Welty rwelty(at)averillpark(dot)net
Averill Park Networking 518-573-7592
Unix, Linux, IP Network Engineering, Security

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Richard Welty 2003-02-07 16:06:44 Re: debugging prepared statements
Previous Message Michael Adler 2003-02-07 15:03:46 new class layout to support COPY protocal