Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database escape char.

 
claude favre
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Is there a function in java similar to the php "stripslashes" function or do I have to parse the string myself before inserting a record to mysql?
Thank you.
claude
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does the "stripslash" function in PHP do?
If you are worried about special characters, then use the prepared statement because it deals with special characters internally.
Jamie
 
claude favre
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It basically deal with special char in text such O'brien, it would in this example escape the apostrophe.
Claude
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a preparedStatement instead of a statement then. It handles the database special characters for you.
This works with prepared statement:

where as it throws a SQLException when using Statement:

SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'emp_fname = 'O'Brien''.

Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic