This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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