Re: Need java.sql.Array impl for PreparedStatement.setArray()
Posted by: Mark Matthews
Date: July 22, 2005 08:38AM

tauron wrote:
> What is the recommended way to implement queries
> like
> SELECT id FROM table WHERE x IN (1,2,3)
> using a PreparedStatement in the current
> Connector/J 3.1.10?
> PreparedStatement pStmt =
> connection.prepareStatement("SELECT id FROM table
> WHERE x IN ?");
> int[] array = {1,2,3};
> pStmt.setString(1, array); // <- won't work
> ResultSet rs = pStmt.executeQuery();

Setup a prepared statement that has as many ?s as your largest array, set all of the values to null first, then set the first "n" values to the value in your array.

btw, java.sql.Array isn't really designed for this, it's designed for an _array_ type, a list of values in IN is not an array.


Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.