在我的JSP中,我使用以下代码从数据库中获取数据:
select * from parks where parkArea = 'abc' AND parkType = 'abcd'
我无法编写语句以在我的JSP中正确执行,这是我尝试过的:
statement = con.prepareStatement("select * from parks ("WHERE parkArea like "abc"") + ("AND parkType = "abcd"")")
我做错了什么?
答案 0 :(得分:2)
select * from parks ("WHERE parkArea like "abc"") + ("AND parkType = "abcd"")"
应该是
"select * from parks WHERE parkArea like 'abc%' AND parkType = 'abcd')"
答案 1 :(得分:0)
con.prepareStatement
("select * from parks WHERE parkArea like \"abc%\" AND parkType = \"abcd\"");
OR
con.prepareStatement
("select * from parks WHERE parkArea like 'abc' AND parkType = 'abcd'");
答案 2 :(得分:0)
可能有一点是你不是escaping your quotes。尝试将内部引号写成\“。如果没有看到错误,很难确定确切的原因。