[英]Call procedure with a table type. Exception while create Struct: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.createStruct
I try to create array of Struct elements to pass it to Oracle procedure. 我尝试创建Struct元素数组以将其传递给Oracle过程。 When I try to set first element of the array I receive an Exception:
当我尝试设置数组的第一个元素时,我收到异常:
java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.createStruct
java.lang.AbstractMethodError:oracle.jdbc.driver.T4CConnection.createStruct
What might be the reason and how to correct this? 可能是什么原因以及如何纠正这个问题? My example:
我的例子:
import java.sql.Array;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Struct;
public class TypesApp {
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.OracleDriver");
Connection connection =
DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.20:1521:dw", "user", "password");
final String typeName = "T_DEMO_OBJECT";
final String typeTableName = "T_DEMO_OBJECTS";
Struct[] structs = new Struct[2];
//Here I get the Exception
structs[0] = connection.createStruct(typeName, new Object[]{23, "Testobject 1"});
structs[1] = connection.createStruct(typeName, new Object[]{40, "Testobject 2"});
CallableStatement callableStatement = connection.prepareCall("{call p_receive_demo_objects(?)}");
Array dataArray = connection.createArrayOf(typeTableName, structs);
callableStatement.setArray(1, dataArray);
callableStatement.executeUpdate();
}
} }
My previous version of the same operation works (with ojdbc6), however it saves numbers to database correctly but all strings are empty, so I try to find another way. 我之前的相同操作版本(使用ojdbc6)可以工作,但是它可以将数字正确保存到数据库中,但是所有字符串均为空,因此我尝试寻找另一种方法。 Previous version:
先前版本:
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;
public class InitMethod2 {
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.OracleDriver");
Connection connection =
DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.20:1521:dw", "user", "password");
final String typeName = "T_DEMO_OBJECT";
final String typeTableName = "T_DEMO_OBJECTS";
final StructDescriptor structDescriptor = StructDescriptor.createDescriptor(typeName.toUpperCase(), connection);
final ArrayDescriptor arrayDescriptor =
ArrayDescriptor.createDescriptor(typeTableName.toUpperCase(), connection);
final ARRAY demoObjectsFromJava = new ARRAY(arrayDescriptor, connection, new STRUCT[]{
// STRUCTS are created with the struct descriptor and a generic object array containing the values of the
// attributes of the T_DEMO_OBJECT
new STRUCT(structDescriptor, connection, new Object[]{23123, "Testobject 1"}),
new STRUCT(structDescriptor, connection, new Object[]{42123, "Testobject 2"})});
CallableStatement cs = connection.prepareCall("{call p_receive_demo_objects(?)}");
cs.setObject(1, demoObjectsFromJava, Types.ARRAY);
cs.execute();
cs.close();
connection.close();
}
}
It was due to ojdbc14.jar . 这是由于ojdbc14.jar造成的 。 When I change it to ojdbc6 (11.2.0.3) the exception is gone.
当我将其更改为ojdbc6(11.2.0.3)时 ,异常消失了。 However in this case you should change method createArrayOf() to this one:
但是,在这种情况下,应将方法createArrayOf()更改为此:
import oracle.jdbc.OracleConnection;
Array dataArray = ((OracleConnection)connection).createOracleArray(typeTableName, structs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.