• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

setArray(...) in DB2

 
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!!!
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • 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.
 
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
Posts: 40200
816
Eclipse IDE VI Editor Java
  • 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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic