oracle clob insertion problem in spring

2.3k views Asked by At

I want to insert CLOB value into my Oracle database and here is the what I could do. I got this exception while inserting operation "ORA-01461: can bind a LONG value only for insert into a LONG column". Would someone able to tell me what should I do? Thanks.

List<Object> listObjects = dao.selectAll("TABLE NAME", new XRowMapper());
String queryX = "INSERT INTO X (A,B,C,D,E,F) VALUES (?,?,?,?,?,XMLTYPE(?))";
OracleLobHandler lobHandler = new OracleLobHandler();
for(Object myObject : listObjects) {
   dao.create(queryX, new Object[]{
     ((X)myObject).getA(),
     ((X)myObject).getB(),
     new SqlLobValue (((X)myObject).getC(), lobHandler),
     ((X)myObject).getD(),
     ((X)myObject).getE(),
     ((X)myObject).getF()
     },
     new int[] {Types.VARCHAR,Types.VARCHAR,Types.CLOB,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR});
}
2

There are 2 answers

0
DCookie On

The first thing I'd do is eliminate either column C or F from your insert to determine which one is causing the error.

1
skaffman On

Are your parameters in the correct order? It's like the SQL statement has the LOB as the 6th parameter, but you're setting the LOB as the 3rd parameter.

Also, I assume getA() to getF() all return String values?