Search code examples
javaoracle-databaseinsertclob

Java: How to insert CLOB into oracle database


I need to write an XML file content into oracle database where the column is of CLOB datatype. How will I do that?


Solution

  • OUTDATED See Lukas Eder's answer below.

    With about 100 lines of code ;-) Here is an example.

    The main point: Unlike with other JDBC drivers, the one from Oracle doesn't support using Reader and InputStream as parameters of an INSERT. Instead, you must SELECT the CLOB column FOR UPDATE and then write into the ResultSet

    I suggest that you move this code into a helper method/class. Otherwise, it will pollute the rest of your code.