Possible Duplicate:
What is the best approach using JDBC for parameterizing an IN clause?
I was wondering if it's possible to pass a list to an SQL statement. I've been Google-ing and most of the answers I found did not make use of a separate .xml file where all the SQL queries were saved.
My sql.xml file contains:
<sql name="getResultSet"><![CDATA[
SELECT ColumnName FROM TableName
WHERE OtherColumnName IN(?)
WITH UR; ]]>
</sql>
In my action.java:
String fileName = "sql.xml";
ListQuery query = new ListQuery(getDefaultsDataSource(), SQLParser.getSql(fileName, "getResultSet"), new int[] {Types.ARRAY});
List rows = (List) query.execute(new Object[] { values });
'values' would be the user input, for example:
values = Name1, Name2, Name3, ...
'values' will be the one in IN(?)
How do I go about this? Is there a better way to do it? Thanks!