我正在使用预准备语句来执行mysql数据库查询.我想基于各种关键字实现搜索功能.
为此我需要使用LIKE
关键字,我知道的很多.我之前也使用过预处理语句,但我不知道如何使用它,LIKE
因为从下面的代码我将添加'keyword%'
?
我可以直接在pstmt.setString(1, notes)
as (1, notes+"%")
或类似的东西中使用它.我在网上看到很多帖子,但在任何地方都没有好的答案.
PreparedStatement pstmt = con.prepareStatement(
"SELECT * FROM analysis WHERE notes like ?");
pstmt.setString(1, notes);
ResultSet rs = pstmt.executeQuery();
Run Code Online (Sandbox Code Playgroud)