helo

Started by beulah prasanthiabout 16 years ago5 messagesbugsgeneral
Jump to latest
#1beulah prasanthi
itsbeulah@gmail.com
bugsgeneral

Helo
I am working on spring project with postgres 8.4
i wrote a function in postgrees which i am passing the argument email
email[] array

From front end we need to insesrt data into that emailarray .so i used

java.arraylist.util
while i am running i got the following error Please help me

error:
org.postgresql.util.PSQLException: Cannot cast an instance of
java.util.ArrayList to type Types.ARRAY

#2Allan Kamau
kamauallan@gmail.com
In reply to: beulah prasanthi (#1)
bugsgeneral
Re: helo

On Mon, Feb 22, 2010 at 2:10 PM, beulah prasanthi <itsbeulah@gmail.com> wrote:

Helo
     I am working on spring project with postgres 8.4
i wrote a function in postgrees which i am passing the argument email
email[] array
From front end we need to insesrt data into that emailarray .so i used
java.arraylist.util
while i am running i got the following error Please help me

error:
org.postgresql.util.PSQLException: Cannot cast an instance of
java.util.ArrayList to type Types.ARRAY

You have cross-posted.

You may want to compose a comma separated values string out of the
values you'd like to send as an array, Then send this string instead
of the array (ofcourse for your postgreSQL function, you will need to
change the datatype of your input variable to TEXT). Then inside your
postgres function unpack the CSV text into an array using some regular
expression(s).

maybe something like this.

Assuming "_my_CSV_string" is your text variable that contains the CSV data.

SELECT * FROM regexp_split_to_array(_my_CSV_string,E',(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))'))AS
my_array;

Allan.

#3Kris Jurka
books@ejurka.com
In reply to: beulah prasanthi (#1)
bugsgeneral
Re: helo

On Mon, 22 Feb 2010, beulah prasanthi wrote:

Helo
     I am working on spring project with postgres 8.4
i wrote a function in postgrees which i am passing the argument email
email[] array
From front end we need to insesrt data into that emailarray .so i used
java.arraylist.util
while i am running i got the following error Please help me

error: 
org.postgresql.util.PSQLException: Cannot cast an instance of
java.util.ArrayList to type Types.ARRAY

You need to pass an instance of java.sql.Array, not a Collection or
something else that is array like.

Also please only report an issue once rather than a half dozen times.

Kris Jurka

#4Kevin Grittner
Kevin.Grittner@wicourts.gov
In reply to: Kris Jurka (#3)
bugsgeneral
Re: helo

Kris Jurka <books@ejurka.com> wrote:

You need to pass an instance of java.sql.Array, not a Collection
or something else that is array like.

Ah, right. After extracting an array from the java.util.ArrayList,
it needs to be turned into a java.sql.Array using the
Connection.createArrayOf method.

Most definitely not a PostgreSQL bug.

-Kevin

#5Wappler, Robert
rwappler@ophardt.com
In reply to: beulah prasanthi (#1)
bugsgeneral
Re: helo

On 2010-02-22, beulah prasanthi wrote:

Helo
I am working on spring project with postgres 8.4
i wrote a function in postgrees which i am passing the
argument email email[] array
From front end we need to insesrt data into that emailarray
.so i used java.arraylist.util
while i am running i got the following error Please help me

error:
org.postgresql.util.PSQLException: Cannot cast an instance of
java.util.ArrayList to type Types.ARRAY

The array support in JDBC is imo nothing better than horrible. However,
the way to go is:
Connection c = getConnection();
Array arr = c.createArrayOf("text", email);

PreparedStatement p = c.prepareStatement(...);
p.setArray(index, arr);

Also notice, that there is no nice way to test array data in frameworks
like DBUnit and others.

--
Robert...