• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setArray(...) in DB2

 
Raj Ganesh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34641
363
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sirish Kumar Gongal Reddy
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34641
363
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic