简体   繁体   中英

How to insert HTML into Oracle DB

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..

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM