Hi,
If you are more concerned about performance than about compatibility,
you could use the TABLE function (only works with H2):
stat.execute("CREATE TABLE TEST(ID INT) AS " +
"SELECT X FROM SYSTEM_RANGE(1, 100)");
PreparedStatement prep;
prep = conn.prepareStatement("SELECT * FROM TABLE(X INT=?, O INT=?) J " +
"INNER JOIN TEST T ON J.X=T.ID ORDER BY J.O");
prep.setObject(1,
new Integer[] { new Integer(30), new Integer(20) });
prep.setObject(2,
new Integer[] { new Integer(1), new Integer(2) });
ResultSet rs2 = prep.executeQuery();
while (rs2.next()) {
System.out.println(rs2.getInt(1));
}
Regards,
Thomas
On Mon, Feb 16, 2009 at 3:58 PM, [email protected] <[email protected]> wrote:
>
> Hi,
>
> I have a list of IDs which I need to fetch from the database. I
> currently use a query of the form:
>
> SELECT * FROM TABLE WHERE ID IN (?,?,?,?,?,....)
>
> I construct the number of parameters dynamically from Java and assign
> the IDs when executing this prepared statement.
>
> However, this technique does not maintain the order. I can, of course,
> sort the rows after fetching. However, for the sake of performance, I
> would prefer a better solution.
>
> One possible approach is to fetch each row individually. I'm not sure
> if this is better. Any help would be appreciated.
>
> Thanks,
> Zviki
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---