I am using a Java app to read thru text files and output them to a SQL script and eventually a Mysql database. One of the columns is made-up of several lines of unformated text, including symbols like commas and apostrophes. To make matters more difficult I have purposely add new lines in order to keep the text readable. Is there a way to have MySQL ignore character combinations that will cause problems (mainly apostrophes, but I have know way of knowing what these blocks of text will contain) without breaking the newlines?
Share
Read through this: http://dev.mysql.com/doc/refman/5.1/en/string-literals.html
In a nutshell, these are the characters to replace
Here is what I have been using for a while in some Java programs where I can’t/don’t use Parameter Binding.
Usage:
StringUtils.addSlashes("ke\rn\tny's\"\nnew li\\ne%"))output:
ke\rn\tny\'s\"\nnew li\\ne\%output viewed in phpmyadmin:
Note: that I’m not really sure about the
\Zimplementation, perhaps someone can elaborate more on that.