Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Apostrophes returned from getText() causing SQL errors

843859Oct 27 2006 — edited Oct 27 2006
I have a seemingly elementary problem, but I can't seem to come up with a simple solution. Look at the following line of code:
s.execute("insert into Requests values ('"+field5.getText().trim()+"','"+tempTime+"','"+tempTime+":  PROBLEM OPENED\n\n"+tempTime+":  "+area.getText()+"','','Open');");
I am using this to add a record to my SQL table. However, whenever there is an apostrophe (') read from the area.getText(), that causes the SQL statement to be improperly executed. I understand why it's causing a problem, but I was wondering if there was a simple solution for it. Or is my only recourse to have my application check every single character in the JTextArea area for apostrophes and insert backslashes before the SQL statement is executed? Thanks for the help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2006
Added on Oct 27 2006
9 comments
336 views