-3

In my JSP I use the following code to fetch data from the database:

select * from parks where parkArea = 'abc' AND parkType = 'abcd' 

I can't write the statement to execute correctly in my JSP, this is what I've tried:

statement = con.prepareStatement("select * from parks ("WHERE parkArea like "abc"") + ("AND parkType = "abcd"")")

What am i doing wrong?

skuntsel
  • 11,624
  • 11
  • 44
  • 67
8900120dd
  • 21
  • 1
  • 2
  • 4

3 Answers3

2
select * from parks ("WHERE parkArea like "abc"") + ("AND parkType = "abcd"")"

should be

"select * from parks WHERE parkArea like 'abc%' AND parkType = 'abcd')"
Satya
  • 8,693
  • 5
  • 34
  • 55
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'");
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
0

One thing it could be is that you are not escaping your quotes. Try writing your inner quotes as \". It is difficult to determine the exact cause without seeing the error you are getting.

Community
  • 1
  • 1
John Kane
  • 4,383
  • 1
  • 24
  • 42