ArrayList and Array

I have an ArrayList with elements and I'm doing

CallableStatement cs = connection.prepareCall(query);

cs.setArray(1, arrayList);

But this gives an error because the method setArray needs as parameter an object that implements the sql.Array

How do I convert a util.ArrayList object into an object that implements sql.Array?

Thanks

[368 byte] By [DesarrolloScreenNamea] at [2007-10-2 22:09:15]
# 1

I did some searching on Google, using the keywords

java using CallableStatement setArray

and I didn't see an easy way to do what you want. I think the underlying purpose of java.util.ArrayList and java.sql.Array are very different. There's probably an easier way to do what you want to do.

I don't claim to be an expert on the topic, having just researched it today. But it looks like you're facing several challenges:

1. the implementation of the java.sql.Array interface is optional in the JDBC specification - so you may need to create an implementation yourself.

2. not all database vendors support the Array type

3. it's not clear whether java.sql.Array is meant for the ? part of a prepared statement such as in "select * from table where column IN ( ? )", if this is what you're trying to do. One poster at http://forums.mysql.com/read.php?39,29488,29506#msg-29506 gave a workaround of

[quote]"The cross-vendor workaround I've seen most people use is to repeat the parameter marker as many times as necessary to hold the largest array the application will need (or have a few prepared statements in the same manner with varying numbers of markers), and then set the leftover parameters to something that is guaranteed to not match the IN clause. Most optimizers deal fine with this."[/quote]

If you need more help, maybe post more of the code so that people can suggest alternate methods to accomplish your goal.

Message was edited by:

Michael_Ebbert

Michael_Ebberta at 2007-7-14 1:26:02 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks for your help. I'll see what I can do
DesarrolloScreenNamea at 2007-7-14 1:26:02 > top of Java-index,Java Essentials,New To Java...