JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom JDBC Developer's Guide - Supra - Cincom

10.07.2015 Views

Example using the Array as input parameterString resortName = "newResort";PreparedStatement stmt =conn.prepareStatement("insert into" +" resort(name,activities) values(?, ?)");stmt.setString(1, resortName);stmt.setArray(2, newActivities);stmt.executeUpdate();stmt.close();// display the new resort activitiesStatement stmt1 = conn.createStatement();rs = stmt1.executeQuery("select a.activity from " + "resort,table(activities) as a(activity)" +" where name = 'newResort'");System.out.println("activities in newResort follow:");while (rs.next())System.out.println(rs.getString(1));rs.close();stmt1.close();stmt.close();// Clean up Cincom ORDB workspace storage used by the collectionif (newActivities != null)newActivities.free();// close the connectionconn.close();}}JDBC Developer's Guide, P25-9504-03 Page 72Chapter: 4. Cincom ORDB ExtensionsSection: Working with Cincom ORDB collections

Collections and custom mappingBy default, the getArray methods of the java.sql.Array interface (implementedby ordbCollection) will return database object references as type java.sql.Ref.The static method ordbCollection.setAutoPerformCustomMapping can be usedto indicate whether getArray should perform custom mapping on databasereferences. The following example shows both behaviors. This sample can befound in the %ORDB%\demo\jdbc\samples\collectionSample5.java file:package demo.jdbc.samples;import java.sql.*;import java.math.*;import java.io.*;import ordbjava.jdbc.*;import java.util.HashMap;//import for custom mappingclass collectionSample5{public static void main (String args []) throws SQLException{// Connect to the demodb database without autocommit enabled.Connection conn = demodbHelper.makeConnection (false);Statement stmt = conn.createStatement();// Build a type map to relate java class jseashore to database class// seashore.try{conn.getTypeMap().put("seashore",Class.forName("demo.jdbc.samples.jseashore"));} catch(ClassNotFoundException e){System.out.println("***Caught SQLException: " + e.getMessage());}JDBC Developer's Guide, P25-9504-03 Page 73Chapter: 4. Cincom ORDB ExtensionsSection: Working with Cincom ORDB collections

Collections and custom mappingBy default, the getArray methods of the java.sql.Array interface (implementedby ordbCollection) will return database object references as type java.sql.Ref.The static method ordbCollection.setAutoPerformCustomMapping can be usedto indicate whether getArray should perform custom mapping on databasereferences. The following example shows both behaviors. This sample can befound in the %ORDB%\demo\jdbc\samples\collectionSample5.java file:package demo.jdbc.samples;import java.sql.*;import java.math.*;import java.io.*;import ordbjava.jdbc.*;import java.util.HashMap;//import for custom mappingclass collectionSample5{public static void main (String args []) throws SQLException{// Connect to the demodb database without autocommit enabled.Connection conn = demodbHelper.makeConnection (false);Statement stmt = conn.createStatement();// Build a type map to relate java class jseashore to database class// seashore.try{conn.getTypeMap().put("seashore",Class.forName("demo.jdbc.samples.jseashore"));} catch(ClassNotFoundException e){System.out.println("***Caught SQLException: " + e.getMessage());}<strong>JDBC</strong> <strong>Developer's</strong> <strong>Guide</strong>, P25-9504-03 Page 73Chapter: 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!