example
Class IdmsExample

java.lang.Object
  extended by example.IdmsExample

public class IdmsExample
extends java.lang.Object

Example JDBC application. This class is an example of a simple JDBC application that reads SQL statements from an input file, executes them, and displays the results on the terminal. usage: java IdmsExample [url=URL] [uid=user-id] [pwd=password] input-file where:

java
command to invoke the Java VM
URL
default is jdbc:idms:JdbcTest
user-id
default is jdbc
password
default is none
input-file
default is stdin

The defaults are the same as those for the IdmsJcf demo program.

This class can also be embedded in an application and used to execute a batch of SQL statements from an input stream, printing the results to a specified output stream.

The input file contains SQL statements formatted more or less as they would be for IDMSBCF,that is, each statement (except the last) must end with a semi-colon or the delimiter specified with the "SET OPTIONS COMMAND DELIMITER '++'" command (exactly this). Comments begin with "--". Blank lines are ignored.

To keep the parsing simple, comments cannot be mixed on the same line as syntax, and all quoted literals and identifiers must be complete on a single line. This is different than IDMSBCF.

Processing stops on any error.

Version:
2.00 10/22/2002
Author:
Dave Ross

Nested Class Summary
protected static class IdmsExample.Arguments
          Internal class that extracts the command line arguments.
 
Field Summary
static java.lang.String DRIVER
          The CA IDMS JDBC driver class name.
protected  java.io.PrintStream out
          When instantiated as a class the output can be redirected.
 
Constructor Summary
IdmsExample()
          Creates an object to process a stream of commands and print to the standard output.
IdmsExample(java.io.PrintStream out)
          Creates an object to process a stream of commands.
 
Method Summary
 void close(java.sql.Connection conn)
          Closes the database connection
 java.sql.Connection connect(java.lang.String url, java.lang.String uid, java.lang.String pwd)
          Connects to a database.
 void execute(java.sql.Connection conn, java.io.InputStream is)
          Executes a batch of commands.
protected  java.lang.String getSql(java.io.BufferedReader in)
          Get the next SQL statement from the input file.
static void main(java.lang.String[] args)
          Stand-alone program entry point.
protected  void print(java.sql.SQLException e)
          Prints a chain of SQLExceptions.
protected  void print(java.lang.String str, int len)
          Prints a string padded with spaces.
protected  void printResultSet(java.sql.ResultSet rs)
          Prints a result set in table format.
protected  void printResultSets(java.sql.Statement stmt)
          Prints all result sets returned for a statement.
protected  void printUpdateCount(java.sql.Statement stmt)
          Prints the number of rows processed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRIVER

public static final java.lang.String DRIVER
The CA IDMS JDBC driver class name.

See Also:
Constant Field Values

out

protected java.io.PrintStream out
When instantiated as a class the output can be redirected.

Constructor Detail

IdmsExample

public IdmsExample()
Creates an object to process a stream of commands and print to the standard output.


IdmsExample

public IdmsExample(java.io.PrintStream out)
Creates an object to process a stream of commands.

Parameters:
out - Print destination.
Method Detail

main

public static void main(java.lang.String[] args)
Stand-alone program entry point.

Parameters:
args - input parameters

connect

public java.sql.Connection connect(java.lang.String url,
                                   java.lang.String uid,
                                   java.lang.String pwd)
Connects to a database.

Parameters:
url - Identifies the database.
uid - User id.
pwd - Password.
Returns:
a connection object or null if an error occurred

execute

public void execute(java.sql.Connection conn,
                    java.io.InputStream is)
Executes a batch of commands.

Parameters:
conn - A connection to a database.
is - Contains the SQL commands.

close

public void close(java.sql.Connection conn)
Closes the database connection

Parameters:
conn - the connection object or null

getSql

protected java.lang.String getSql(java.io.BufferedReader in)
Get the next SQL statement from the input file.

Parameters:
in - the input file's reader
Returns:
the SQL statement or null
Throws:
java.sql.SQLException - if an error occurs

printResultSets

protected void printResultSets(java.sql.Statement stmt)
                        throws java.sql.SQLException
Prints all result sets returned for a statement.

Parameters:
stmt - the statement just executed
Throws:
java.sql.SQLException - if an error occurs

printResultSet

protected void printResultSet(java.sql.ResultSet rs)
                       throws java.sql.SQLException
Prints a result set in table format.

Parameters:
rs - the result set just opened
Throws:
java.sql.SQLException - if an error occurs

printUpdateCount

protected void printUpdateCount(java.sql.Statement stmt)
                         throws java.sql.SQLException
Prints the number of rows processed

Parameters:
stmt - the statement just executes
Throws:
java.sql.SQLException - if an error occurs

print

protected void print(java.lang.String str,
                     int len)
Prints a string padded with spaces.

Parameters:
str - the string
len - the max length

print

protected void print(java.sql.SQLException e)
Prints a chain of SQLExceptions.

Parameters:
e - the first exception


Copyright © 2009 CA, All rights reserved