我想将此Access sql查询转换为Java JDBC
Select *
From books
Where Lcase(title) LIKE Lcase('*jdbc*') AND Lcase(title) LIKE Lcase('*programming*')
我使用像这样的preparedStatement
String sql1="Select * From books Where Lcase(title) LIKE Lcase(%?%) AND Lcase(title) LIKE Lcase(%?%)";
PreparedStatement ps1=con.prepareStatement(sql1);
ps1.setString(1, "jdbc");
ps1.setString(2, "programming");
ResultSet rs1=ps1.executeQuery();
但是我收到语法错误
答案 0 :(得分:4)
如果您想将%
插入Lcase
使用的值,您有两种选择:
%
或第一种方法如下:
String sql1="Select * From books Where Lcase(title) LIKE Lcase(?) AND Lcase(title) LIKE Lcase(?)";
PreparedStatement ps1=con.prepareStatement(sql1);
ps1.setString(1, "%jdbc%");
ps1.setString(2, "%programming%");
第二种方法如下:
String sql1="Select * From books Where Lcase(title) LIKE Lcase('%' & ? & '%') AND Lcase(title) LIKE Lcase('%' & ? & '%')";