Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to write select query when where condition contains ampersand symbol(&)?

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to write a select query when where condition contains ampersand(&) symbol?

example:

select * from subjects where name='abc & xyz';
 
George Stoianov
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the RDBM's character escape sequence, or you might consider using a prepared statement with the respective driver and this should be taken care of auto-magically.
 
Leandro Dantas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

The best approach is use the PreparedStatment as George Stoianov pointed out.

using the setString method will let the driver use the correct method to escape the symbol.

Regards.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhishek Reddy Chepyala:
how to write a select query when where condition contains ampersand(&) symbol?

example:

select * from subjects where name='abc & xyz';


select * from subjects where name='abc &'||'xyz'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic