1

I got to insert HTML into a column of a Oracle DB table. I created the insert statement, and used apache commons StringEscapeUtils.Escapesql and StringEscapeUtils.EscapeHtml to try to insert that HTML. But i am getting a SQL Command not properly ended exception.

If i insert null then statement goes through fine. Please help..

1 Answer 1

5

You shouldn't have to use any of those escape methods.

There is no need to escape the HTML. Escaping the HTML is useful when some user writes some text and you want to display it as is, inside an HTML page. So you want > to be transformed to >, etc. The database doesn't need this, and you would have to unescape it when loading it from the database to get your HTML back. That's completely unnecessary.

The HTML has to be SQL-escaped, but that's the job of the JDBC driver. Just use prepared statements, and bind the HTML string using the setString() method, and the driver will escape everything for you. Read the JDBC tutorial.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.