JDBC: RMS Bridge Example

From Recital Documentation Wiki
Revision as of 14:57, 26 March 2009 by Yvonnemilne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/*#=======================================================================
 *# Copyright (C) 2006 Recital Corporation Inc.
 *# As an unpublished licensed proprietary work.
 *# All rights reserved worldwide.
 *#=======================================================================
 * MODULE : rms_test.java
 * PURPOSE : Recital Universal JDBC Driver RMS 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 rms_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 RMS table on the server
			//-----------------------------------------------------------------------
			System.out.println("Create Metadata file rmsdemo.str.");
			stmt.execute("create table rmsdemo.str " +
						 "(ord_no char(8), " +
						 "ord_date date," +
						 "name char(20)," +
						 "street char(25)," +
						 "city char(25)," +
						 "state char(13)," +
						 "goods char(40)," +
						 "order_value num(11,2)," +
						 "rec_date date," +
						 "paid_date date," +
						 "paid_value num(11,2)," +
						 "acc_start date," +
						 "acc_end date," +
						 "acc_prefix char(3)," +
						 "acc_no char(5)," +
						 "batch_no char(4))");
 
			//-----------------------------------------------------------------------
			//-- Create Bridge file
			//-----------------------------------------------------------------------
			System.out.println("Create Bridge File rmsdemo.dbf.");
			stmt.execute("create bridge rmsdemo.dbf " +
					 "type 'RMSIDX' "+
					 "external 'rmsidx.dat' " +     // Name of the RMS data file.
					 "metadata 'rmsdemo.str' "+     // Name of the Metadata file.
					 "alias 'rmsdemo'" +
					 "index 'acc_prefix+acc_no'");
 
			//-----------------------------------------------------------------------
			//-- Query for data
			//-----------------------------------------------------------------------
			System.out.println("Select rows from rmsdemo.");
			rs = stmt.executeQuery("SELECT * from rmsdemo");
			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) {
			;
		}
	}
}


See also: C-ISAM Data Files