10.07.2015 Views

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public static void main (String args []) throws SQLException{// Connect to the demodb database without autocommit enabled.Connection conn = demodbHelper.makeConnection (false);// get a homogeneous collection of a primitive data typeStatement stmt = conn.createStatement();stmt.executeUpdate("create class primitive(int_set set of int)");stmt.executeUpdate("insert into primitive " +"values({1,2,3,4,5,null})");ResultSet rs = stmt.executeQuery("select int_set from primitive");rs.next();ordbCollection intSet = (ordbCollection)rs.getArray("int_set");rs.close();try {// get first 5 elements into int array (skip null)int [] intArray = (int [])intSet.getArray(1, 5);for (int i = 0; i < intArray.length; i++)System.out.println("element: " + i + " int value: " + intArray[i]);} catch (SQLException e) {System.out.println("Error, should not get to this exception");}// now try to include the null, handle the exceptiontry {int [] intArray = (int [])intSet.getArray();} catch (SQLException e) {// try as object arraySystem.out.println("Exception: " + e.getMessage());System.out.println("try again as array of objects");intSet.setAlwaysReturnObjects(true);Object [] IntegerArray = (Object [])intSet.getArray();for (int i = 0;i < IntegerArray.length; i++)System.out.println("element" + i + " object value: " +(Integer)IntegerArray[i]);}<strong>JDBC</strong> <strong>Developer's</strong> <strong>Guide</strong>, P25-9504-03 Page 68Chapter: 4. <strong>Cincom</strong> ORDB ExtensionsSection: Working with <strong>Cincom</strong> ORDB collections

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!