Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Special Character Handling

 
rakesh damkondwar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the documentation on PreparedStatements. If you bind a variable, you no longer have to worry about escaping special charaters.
 
rakesh damkondwar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for that. And is there any special handling to be done while using java.sql.Statement and not PreparedStatement ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic