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

special characters in queries

 
pavanasree vasireddy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with special characters in java.

I am entering a big string which may consist of special character especially quotes("). I need to insert in to the database as string. I am using MYSQL.
In MySql Strings need to be enclosed with quotes.

My problem is when i insert strings which consists of quotes it is giving error as it is not able to identify the quotes that are enclosed and the quotes that are within the string.


please help me in this regard.

[EJFH: Added meaningful subject ]
[ August 12, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the java.sql.PreparedStatement class. You prepare your query using question marks ("?") as placeholders, and then PreparedStatement does the work of escaping the special characters in your strings for you. Works great.

I'm going to move this to our JDBC forum for followup.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic