Hi.. I have a text box in which the description of a problem is written .... the textbox name is prdesc ; now when prdesc holds the value = " dont or doesnot " ... this string doesn't give a problem but if my string contains special characters such as " Don't or Doesn't or "double quotes " " .... it gives a problem while inserting in mysql database...!!! it checked out in the database .. it inserts a "\" before every single and double quotes...... how would i handle this in jsp .. my insert command at the time being is insert into some table(problem)values ('"+prdesc+"'); ???
Hi Mehak, The single and double quotes have caused me a lot of frustration in the past. I don't know about the mysql database, but here is what I think is happening You have this mystring = "don't" then you have strSQL = "INSERT INTO myTable(myField) VALUES('mystring')" it is seeing the ' in don't as the end of the string and then it doesn't know what to do with the t I generally will use the replace method to replace ' with ` in the variable the \ you are seeing means to take the next character literally, so any character following the \ should process (*I think*), but I do not know how it will affect your output. hope this helps, Lisa M.
I agree with Tim Baker. The best approch is to use PreparedStatements.
Here you use setXXX to map the ? to a variable. When you use ps.setString( 1 , UserName ); you map the UserName variable with the first ? character. There are more methods than setString of course. See java.sql.PreparedStatement for more information
SCJP2 , MCP( 70-229 ) , Preparing For SCWDC
posted 15 years ago
Thanks for posting this question Mehak - and please ingnore my primitive response! SHEESH!!! Why do I always insist on doing things the difficult way?!? :roll:
posted 15 years ago
hey guys ... thanx for ue suggestion....... i was getting the same problem with the prepared statement ... but the newstr.replace() function really helped ... thanx .... a lot..!!