我尝试进行动态不区分大小写的搜索,但最终我的参数索引超出范围(1>参数个数,为0)
java.sql.PreparedStatement preStatement = connect.prepareStatement
"SELECT word1 from words WHERE word2 like '%?%'");
preStatement.setString(1, word);
ResultSet rs = preStatement.executeQuery();
答案 0 :(得分:0)
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