简体   繁体   中英

JDBC: How to pass List of object into preparedStatement, or for a better alternative

I have a question about JDBC.

PreparedStatement preparedStatement = 
      dbConnection.prepareStatement(
             "SELECT userid, roleid, name from permission 
              where (userid, roleid) in (?)");

// assume I cannot update the above line, which is maintained by others

// now I just get a PreparedStatement and a list of object
Set<Pair<Integer, Integer>> idPair = ....

How can I execute the query with idPair variable?

PS: ( userid , roleid ) together are primary key for permission table

Thank you so much!

You can not.

You need to resort to plain SQL with iteration and filtering.

This is not JDBC specific, but AFAIK universal to most drivers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM