Results 1 to 6 of 6
Thread: PreparedStatement and Arrays
- 01-04-2010, 01:22 PM #1
PreparedStatement and Arrays
Okay, now this is tricky and google didnt help much (only to relize this is a difficult problem)
I use postgresql so i will do it in that dislaect.
Here the query:
I have this simple query (in pgadmin3)
it returns an array and it is great ;-)Java Code:select '{1,3}'::int[]
but in my code i want to use a prepared statement
now the question: which method should i use to set the value?Java Code:PreparedStatement s = connection.prepareStatement("select ?::int[]");
if i e.g. use s.setString(1,"{1,3}") i have a cast exception.
so which one is right?
thanks in advance"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 01-04-2010, 01:27 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Did you try the setArray method?
- 01-04-2010, 04:21 PM #3
no, like i said the setArray method does not really work, as i have to implement the java.sql.Array myself.
but i found the solution:
this converts a string to an array and therefore all i have to to do isJava Code:select string_to_array('1,2,3',',')
Java Code:PreparedStatement s = connection.prepareStatement("select string_to_array(?,' '));"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 01-04-2010, 04:22 PM #4
btw: how do i mark as solved ?
"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 01-04-2010, 06:59 PM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 01-04-2010, 07:07 PM #6
sry, my bad :-) forget to mention. but many google hits said that setArray is optional and is only possible for oracle db without own implementation of the Array interface.
"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
Similar Threads
-
Regarding PreparedStatement
By adeeb in forum JDBCReplies: 0Last Post: 06-09-2008, 09:07 PM -
Using PreparedStatement
By Java Tip in forum Java TipReplies: 0Last Post: 12-22-2007, 11:24 AM -
PreparedStatement
By Java Tip in forum Java TipReplies: 0Last Post: 12-05-2007, 03:56 PM -
Help me. PreparedStatement
By Felissa in forum JDBCReplies: 2Last Post: 06-28-2007, 05:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks