我想在表中搜索包含子字符串的标题(在我的情况下,子字符串是传递给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();
}
}