This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Special Character Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Special Character Handling" Watch "Special Character Handling" New topic
Author

Special Character Handling

rakesh damkondwar
Greenhorn

Joined: Sep 17, 2004
Posts: 9
Hello,

I am using DB2 database. I have one table which has a column of Varchar(String) data type. I want to insert following value into that column.

`~!@#$%^&*()_+<>?,./:;"'

In short i want to take care of any special character entered by user. Please help me on this issue ..

Thanks in advance.
~Rakesh
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Read the documentation on PreparedStatements. If you bind a variable, you no longer have to worry about escaping special charaters.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
rakesh damkondwar
Greenhorn

Joined: Sep 17, 2004
Posts: 9
thanks for that. And is there any special handling to be done while using java.sql.Statement and not PreparedStatement ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you use Statement you can think of it in the same way as opening any database client application and just typing in SQL. You get maximim flexability, but its up to you to handle all the possible issues, such as special characters. So you will need to handle any characters which can break your SQL statement in the SQL statement itself (escaping quotes, properly formatting dates etc).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Special Character Handling