File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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).
 
 
subject: Special Character Handling
 
Similar Threads
Taking entries from database containing %
How to remove special/hidden characters from a string with a regex expression
Special characer in Database + problem in trimming it with trim()
Oracle Insert query in Java
Encoding of special characters in the request parameter