|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object example.IdmsExample
public class IdmsExample
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:
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.
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 |
---|
public static final java.lang.String DRIVER
protected java.io.PrintStream out
Constructor Detail |
---|
public IdmsExample()
public IdmsExample(java.io.PrintStream out)
out
- Print destination.Method Detail |
---|
public static void main(java.lang.String[] args)
args
- input parameterspublic java.sql.Connection connect(java.lang.String url, java.lang.String uid, java.lang.String pwd)
url
- Identifies the database.uid
- User id.pwd
- Password.
public void execute(java.sql.Connection conn, java.io.InputStream is)
conn
- A connection to a database.is
- Contains the SQL commands.public void close(java.sql.Connection conn)
conn
- the connection object or nullprotected java.lang.String getSql(java.io.BufferedReader in)
in
- the input file's reader
java.sql.SQLException
- if an error occursprotected void printResultSets(java.sql.Statement stmt) throws java.sql.SQLException
stmt
- the statement just executed
java.sql.SQLException
- if an error occursprotected void printResultSet(java.sql.ResultSet rs) throws java.sql.SQLException
rs
- the result set just opened
java.sql.SQLException
- if an error occursprotected void printUpdateCount(java.sql.Statement stmt) throws java.sql.SQLException
stmt
- the statement just executes
java.sql.SQLException
- if an error occursprotected void print(java.lang.String str, int len)
str
- the stringlen
- the max lengthprotected void print(java.sql.SQLException e)
e
- the first exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |