PreparedStatement IN clause alternatives?

前端 未结 30 4483
情歌与酒
情歌与酒 2020-11-21 05:19

What are the best workarounds for using a SQL IN clause with instances of java.sql.PreparedStatement, which is not supported for multiple values du

30条回答
  •  轮回少年
    2020-11-21 05:38

    instead of using

    SELECT my_column FROM my_table where search_column IN (?)
    

    use the Sql Statement as

    select id, name from users where id in (?, ?, ?)
    

    and

    preparedStatement.setString( 1, 'A');
    preparedStatement.setString( 2,'B');
    preparedStatement.setString( 3, 'C');
    

    or use a stored procedure this would be the best solution, since the sql statements will be compiled and stored in DataBase server

提交回复
热议问题