aspose file tools*
The moose likes JDBC and the fly likes setArray(...) in DB2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "setArray(...) in DB2" Watch "setArray(...) in DB2" New topic
Author

setArray(...) in DB2

Raj Ganesh
Greenhorn

Joined: Apr 22, 2005
Posts: 1
Hello,

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);
callTest.execute();
callTest.close();

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
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

Raj,
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.


[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
Hi!
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
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

Sirish,
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setArray(...) in DB2