insertSQL = "insert into TELBP_INPUT_LOG (SERIAL_NO, INPUT_XML) values (?, ?)";
statement = connection.prepareStatement(insertSQL);
statement.setString(1, serialNo);
statement.setString(2, inXml);
//statement.setString(2, "test");
insertCount = statement.executeUpdate();
当程序运行executeUpdate()时,错误
java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
被抛出,但是如果我复制serialNO和inXml的值并在SQL开发人员中运行,没有提示错误,是什么原因?
答案 0 :(得分:2)
您无法将字符串写入Clob列。
而不是
statement.setString(2, inXml);
使用
statement.setClob(2, xmlClob);
首先需要创建xmlClob:
Clob xmlClob = connection.createClob();
Writer clobWriter = myClob.setCharacterStream(1);
clobWriter.write(inXml);
答案 1 :(得分:1)
对于clob
字段,您可以使用。setClob(..)
setString():Sets the designated parameter to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database.
答案 2 :(得分:1)
Java(底层驱动程序)将CLOB视为字符流。当您设置String时,底层驱动程序实现将自动执行相关转换(String to Varchar等)。由于CLOB是一种特殊类型,程序员有责任采取必要的步骤。点击链接到现在如何使用java插入clob: http://docs.oracle.com/javase/tutorial/jdbc/basics/blob.html