Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing arrays to oracle

 
Stu Johns
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to pass an array of Strings to insert into an oracle table in 1 hit.
I have defined types in oracle:



and have written the code:


However I get an error when i try and run it:
Exception in thread "main" java.sql.SQLException: Fail to convert to internal representation: v4
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:239)
at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:274)
at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:115)
at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:1314)
at oracle.sql.ARRAY.<init>(ARRAY.java:152)
at TestArray.main(TestArray.java:63)


Anyone got any ideas how to do an insert with an array in oracle?

thanks


 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stu Johns wrote:
I have defined types in oracle:



I don't have much experience with Oracle, so this could be wrong, but shouldn't col1 be of type array_of_persons..?
 
Anil Kumar Saha
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look into it. It may help
http://agilej.blogspot.com/2009/05/passing-oraclesqlarray-to-stored.html
 
Stu Johns
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks folks.
Lorand you were right the columns didnt match.
Anil your example was a great link, I have decided to go the package route for my solution.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic