Inserting large XMLTYPE

Posted by Steve Racanovic | Posted in | Posted on 10:34 AM


When inserting large XMLTYPE, I am left with the following error:

java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.T4CTTIoer.processError(
at oracle.jdbc.driver.T4CTTIoer.processError(
at oracle.jdbc.driver.T4C8Oall.receive(
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(
at InsertXML.insertXMLType(
at InsertXML.main(

I found 2 ways to get around this problem.

1. XMLType are opaque types, so I should be using oracle.xdb.XMLType. So my code should look something like:

XMLType xml;
byte[] byteBuffer = xmlDetails.toString().getBytes();
InputStream is = new ByteArrayInputStream(byteBuffer);
xml = XMLType.createXML(connection,is);

2. In Oracle JDBC (Not implemented in and using JDK 1.6 (utilising JDBC 4.0) we can use SQLXML Type - java.sql.SQLXML

So the code should look something like:

SQLXML x = conn.createSQLXML();
pstmt.setSQLXML(1, x);

The second option here is preferred and moving forward.

Comments (0)