Inserting an OBJECT Value into an Oracle Table Using a Prepared Statement - Java JDBC

Java examples for JDBC:Oracle

Description

Inserting an OBJECT Value into an Oracle Table Using a Prepared Statement

try {
    Object[] object2Values = new Object[]{"str", new BigDecimal(123)};
    oracle.sql.StructDescriptor structDesc =
        oracle.sql.StructDescriptor.createDescriptor("OBJECT2", connection);
    oracle.sql.STRUCT object2 =
        new oracle.sql.STRUCT(structDesc, connection, object2Values);

    Object[] object1Values = new Object[]{"str", object2};
    structDesc = oracle.sql.StructDescriptor.createDescriptor("OBJECT1", connection);
    oracle.sql.STRUCT object1 =
        new oracle.sql.STRUCT(structDesc, connection, object1Values);

    PreparedStatement ps =
        connection.prepareStatement("INSERT INTO object1_table VALUES(?,?)");

    ps.setInt(1, 123);
    ps.setObject(2, object1);

    ps.execute();
} catch (SQLException e) {
}

Related Tutorials