Getting a VARRAY Value from an Oracle Table - Java JDBC

Java examples for JDBC:Oracle

Description

Getting a VARRAY Value from an Oracle Table

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
  public static void main(String[] argv) {
    try {
      Connection connection = null;
      Statement stmt = connection.createStatement();
      // Select rows from varray_table
      ResultSet resultSet = stmt.executeQuery("SELECT * FROM varray_table");

      // Get the VARRAY values from each row
      while (resultSet.next()) {
        // Get the VARRAY value in the first column
        oracle.sql.ARRAY array = ((oracle.jdbc.driver.OracleResultSet) resultSet)
            .getARRAY(1);

        // Get the VARRAY elements; values.length is the number of values in the
        // VARRAY
        java.math.BigDecimal[] values = (java.math.BigDecimal[]) array
            .getArray();
      }
    } catch (SQLException e) {
    }
  }
}

Related Tutorials