我想在表中搜索包含子字符串的標題(在我的情況下,子字符串是傳遞給getBookForTitle
方法的標題)。問題是它不會返回任何東西。使用佔位符搜索postgresql
public void getBookForTitle(String title) {
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = connection.prepareStatement("Select * from books where name like '%?%'; ");
rs = stm.executeQuery();
while (rs.next()) {
System.out.print(rs.getInt(1));
System.out.print(": ");
System.out.print(rs.getString(1));
System.out.println(rs.getBoolean(3));
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}