Dao Lam
Dao Lam

Reputation: 2937

How to escape parentheses in jsp

I keep getting errors on this line of code:

pstmt = conn.prepareStatement( "SELECT * FROM products WHERE category IN" +
"(" + "SELECT catid FROM category WHERE name= currentcat " + ")" );

I'm guessing the problem is my parentheses. If it's not then what's wrong with my code? Thank you!

Upvotes: 0

Views: 165

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

It has nothing to do with parentheses. A varchar value must be surrounded by single quotes in SQL:

SELECT catid FROM category WHERE name = 'currentcat'

The error message, which you didn't post, usually contains meaningful information. Always read (and post) the complete and exact error message.

Upvotes: 1

Related Questions