This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes setArray(...) in DB2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "setArray(...) in DB2" Watch "setArray(...) in DB2" New topic

setArray(...) in DB2

Raj Ganesh

Joined: Apr 22, 2005
Posts: 1

I'm trying to set an array to my Callable Statement. I have an ArrayList and i convert it into Array by,

//arrayList is my ArrayList object with string values
//Database is DB2 running on AS400

Class arrayClass = ((Object)arrayList).getClass();
Class componentClass = arrayClass.getComponentType();
Object o = java.lang.reflect.Array.newInstance(componentClass, 5);

CallableStatement callTest = connection.prepareCall("call test10(?)");
callTest.setObject(1, (java.sql.Array) o);

It gives me ClassCastException when Object o is casted to Array. I tried other straight forward methods, But did not work. Does anyone have an idea about this? Please help!!!
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32328

Welcome to JavaRanch!

Since ArrayList does not implement the Array interface, no ammount of casting is going to let you do this. In fact you are better off not using reflection. That way you get a compiler error instead of a runtime error. I think you have to use the database specific implementation class of Array.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sirish Kumar Gongal Reddy
Ranch Hand

Joined: Oct 25, 2004
Posts: 109
1)How can i lock an Object ? (not class)

2)How i can create programetic connection Pooling and how can i access it ?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32328

Welcome to JavaRanch!

Is this related to the original question? If not, it's ok to start a new thread (for the future)

1) What kind of object? A database row? A java object? Data in a java object?
2) You can use a connection pool provided by your server (like tomcat) or a third party implementation (like the one in jakarta commons)
It is sorta covered in the JavaRanch Style Guide.
subject: setArray(...) in DB2
It's not a secret anymore!