e299. getting an object value from an oracle table.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 34 行

TXT
34
字号
This example retrieves values contained in an Oracle OBJECT type. The example uses the table and types created in e296 Creating an OBJECT Type in an Oracle Database. 
    try {
        // Create a statement
        Statement stmt = connection.createStatement();
    
        // Select rows from object1_table
        ResultSet resultSet = stmt.executeQuery("SELECT * FROM object1_table");
    
        // Get the OBJECT values from each row
        while (resultSet.next()) {
            // Get the integer from the first column col_integer of the row
            int i = resultSet.getInt(1);
    
            // Get the object1 value from the second column col_object1
            oracle.sql.STRUCT object1 = (oracle.sql.STRUCT)resultSet.getObject(2);
    
            // Get the object1 values from each row
            Object[] object1Values = object1.getAttributes();
    
            // Get the first value of object1, which is a string
            String str = (String)object1Values[0];
    
            // Get the second value of object1, which is of the type object2
            oracle.sql.STRUCT object2 = (oracle.sql.STRUCT)object1Values[1];
    
            // Get the values of object2
            Object object2Values[] = object2.getAttributes();
            str = (String)object2Values[0];
            BigDecimal num =  (BigDecimal)object2Values[1];
        }
    } catch (SQLException e) {
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?