HycelTaylor
asked on
How to insert text with double quotes and semi colins in an insert statement
I have to use a created sql statement to insert into a table. One of the colums needs to take a short sentance. A sentance may have double quotes (") and semi colins (,).
Example: This, is a "Test"
My code is the following:
sql = new StringBuilder("insert into t_content (activation_datetime, text, ) values (");
sql.append(dateFormat.form at(content .getActiva tionDateTi me())).app end(COMMA) ;
String text = content.getText();
// do something to the text here
sql.append(text);
sql.append(")");
insertStatment.addBatch(sq l.toString ());
I also need to make sure that once the text is save to the database it's back into it original format.
I need a solution to this problem urgently.
Thanks for any help in this matter.
Example: This, is a "Test"
My code is the following:
sql = new StringBuilder("insert into t_content (activation_datetime, text, ) values (");
sql.append(dateFormat.form
String text = content.getText();
// do something to the text here
sql.append(text);
sql.append(")");
insertStatment.addBatch(sq
I also need to make sure that once the text is save to the database it's back into it original format.
I need a solution to this problem urgently.
Thanks for any help in this matter.
ASKER
The insert statement would look like the following:
insert into t_content(1000,This, is a \"Test\");
I think that I would still need to place something around the sentance so that the comma would not be mistaken for a column separator.
What should I place around the sentance?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
you should only need to replace the following characters:-
carraige return -> \r
line feed -> \n
tab -> \t
' -> \'
" -> \"