This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes special characters in queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "special characters in queries" Watch "special characters in queries" New topic
Author

special characters in queries

pavanasree vasireddy
Ranch Hand

Joined: Jun 12, 2004
Posts: 34
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

Joined: Jul 08, 2003
Posts: 24189
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: special characters in queries
 
jQuery in Action, 3rd edition