在java中创建oracle类型

时间:2011-10-20 06:54:51

标签: java oracle types

我想调用一个oracle函数,它在 oracle类型的参数类型中选择一个,在 oralce types 中引用一个参数类型。

代码:

Connection connection = (Connection) parameters.get(SwingBenchTask.JDBC_CONNECTION);
boolean success = true;
// getObjArray returns one object array with values
Object[] object2Values = getObjArray("input.txt");
oracle.sql.StructDescriptor structDesc = oracle.sql.StructDescriptor.createDescriptor(typeName, connection);
oracle.sql.STRUCT object1 = new oracle.sql.STRUCT(structDesc, connection, object2Values);
String query = "{call ? :=change_offer(?,?)}";
CallableStatement stmt = connection.prepareCall(query);
long executeStart = System.nanoTime();
try
{
    stmt.registerOutParameter(1, OracleTypes.NUMBER);
    stmt.setObject(2, object1, OracleTypes.STRUCT);
    stmt.registerOutParameter(3, OracleTypes.STRUCT, OutTypeName);
    stmt.execute();
    stmt.close();
} catch (Exception ex)
{
    success = false;
    System.err.println("Error :" + ex);
}

类oralce.sql.STRUCT的构造函数抛出异常

java.sql.SQLException:ORA-01427:单行子查询返回多行

1 个答案:

答案 0 :(得分:1)

我修正了错误。我给出了带有模式名称的类型名称。

oracle.sql.StructDescriptor structDesc = oracle.sql.StructDescriptor.createDescriptor(schema.typeName, connection);
oracle.sql.STRUCT object1 = new oracle.sql.STRUCT(structDesc, connection, object2Values);