我正在尝试进行不区分大小写的动态搜索,但即时通讯最终导致参数索引超出范围(1>参数数量,即0)

     java.sql.PreparedStatement preStatement = connect.prepareStatement
                            "SELECT word1 from words WHERE word2 like '%?%'");
     preStatement.setString(1, word);
     ResultSet rs = preStatement.executeQuery();

最佳答案

java.sql.PreparedStatement preStatement = connect.prepareStatement
                            "SELECT word1 from words WHERE word2 COLLATE UTF8_GENERAL_CI like '?'");
preStatement.setString(1, "%"+word+"%");
ResultSet rs = preStatement.executeQuery();


那时调用setString() api时,请使用表达式。

对于不区分大小写的搜索,您必须在喜欢之前添加COLLATE UTF8_GENERAL_CI

10-08 04:01