JDBC: C-ISAM Bridge Example
From Recital Documentation Wiki
Revision as of 14:54, 26 March 2009 by Yvonnemilne (Talk | contribs)
See Also
/*#======================================================================= *# Copyright (C) 2006 Recital Corporation Inc. *# As an unpublished licensed proprietary work. *# All rights reserved worldwide. *#======================================================================= * MODULE : cisam_test.java * PURPOSE : Recital Universal JDBC Driver CISAM file access * AUTHOR : Recital Corporation * DATE : Aug-2006 *======================================================================*/ //----------------------------------------------------------------------- //-- Standard imports required by Recital JDBC Driver //----------------------------------------------------------------------- import java.sql.*; import java.io.*; import java.net.URL; import java.math.BigDecimal; import Recital.sql.*; public class cisam_test { public static void main(String argv[]) { int i; ResultSet rs; ResultSetMetaData rsmd; try { //----------------------------------------------------------------------- //-- Load the Client Driver for the //-- Recital Database Server //----------------------------------------------------------------------- new RecitalDriver(); //----------------------------------------------------------------------- //-- Build the connection URL: //----------------------------------------------------------------------- String url = "jdbc:Recital:" + "SERVERNAME=servername;" + "DATABASE=jdbc_test;" + "USERNAME=username;" + "PASSWORD=password"; //----------------------------------------------------------------------- //-- Connect //----------------------------------------------------------------------- Connection con = DriverManager.getConnection(url); //----------------------------------------------------------------------- //-- Create a statement on the connection //----------------------------------------------------------------------- Statement stmt = con.createStatement(); //----------------------------------------------------------------------- //-- Query info from the driver //----------------------------------------------------------------------- DatabaseMetaData dbmd = con.getMetaData(); System.out.println(dbmd.getDriverVersion() + "\n" + dbmd.getDriverName()); //----------------------------------------------------------------------- //-- Create table to define the metadata of the CISAM table on the server //----------------------------------------------------------------------- System.out.println("Create meta data file cisamdemo.str."); stmt.execute("create table cisamdemo.str " + "(dd char(4), " + "confirm char(6)," + "procdate char(6)," + "control char(5)," + "dollars num(13,2)," + "dealer char(5)," + "territory char(2)," + "worep char(12)," + "currtan char(3)," + "traddate char(6)," + "city char(10)," + "account char(11)," + "pretran char(2)," + "afsrep char(14)," + "repkey char(9)," + "branch char(3)," + "wodealer char(5)," + "bankcode char(2)," + "commrate num(6,4)," + "newrep char(1)," + "settle char(1)," + "postdate char(6))"); //----------------------------------------------------------------------- //-- Create Bridge file //----------------------------------------------------------------------- System.out.println("Create Bridge File cisamdemo.dbf."); stmt.execute("create bridge cisamdemo.dbf " + "type 'CISAM' "+ "external 'cisamdemo' " + // Name of the CISAM data file. "metadata 'cisamdemo.str' "+ // Name of the Metadata file. "alias 'cisamdemo'"); //----------------------------------------------------------------------- //-- Query for data //----------------------------------------------------------------------- System.out.println("Select rows from cisamdemo."); rs = stmt.executeQuery("SELECT * from cisamdemo"); rsmd = rs.getMetaData(); int nr_cols = rsmd.getColumnCount(); while (rs.next()) { for (i = 1; i <= nr_cols; i++) { System.out.println("rs Column[" + i + "] : " + rsmd.getColumnName(i) + " <" + rsmd.getColumnTypeName(i) + "> = " + rs.getString(i)); } System.out.println("Got results:"); } //----------------------------------------------------------------------- //-- Release the statement //----------------------------------------------------------------------- stmt.close(); //----------------------------------------------------------------------- //-- Disconnect from the server //----------------------------------------------------------------------- con.close(); } catch (Exception e) { System.out.flush(); System.err.flush(); DriverManager.println("Recital JDBC driver exception: " + e.getMessage()); e.printStackTrace(); } try { System.out.println("Press any key to continue..."); System.in.read(); } catch(IOException ie) { ; } } }