Table of contents:

  Info
  Requirements
  Introduction
    1,2,3-Tier Solutions
    Further Informations ...
    Copyrights
  Classes
    Classes of the ODBC interface
      class J2ODBC
        constants
        constructors
        allocConnect()
        allocEnv()
        allocStmt()
        bindCol()
        browseConnect()
        cancel()
        clone()
        collAttributes...()
        columns()
        connect()
        describeCol...()
        describeParam...()
        disconnect()
        driverConnect()
        error()
        execDirect()
        execute()
        extendedFetch()
        fetch()
        foreignKeys()
        freeConnect()
        freeEnv()
        freeStmt()
        getConnectOption...()
        getCursorName()
        getData...()
        getInfoNum(), getInfoStr()
        getStmtOption...()
        getTypeInfo()
        moreResults()
        nativeSql()
        numParams()
        numResultCols()
        paramData()
        paramOptions...()
        prepare()
        primaryKeys()
        procedures()
        procedureColumns()
        putData()
        rowCount()
        setConnectOption...()
        setCursorName()
        setParam()
        setPos()
        setScrollOptions()
        setStmtOption...()
        specialColumns()
        statistics()
        tablePrivileges()
        tables()
        transact()
      class J2ODBCException
        constructors
      class J2ODBCWarning
        constructors
    Classes of the JDBC interface
      Class JdbcOdbcCallableStatement
        constructors
        get...()
        registerOutParameter()
        wasNull()
      Class JdbcOdbcConnection
        definitions
        constructors
        destructors
        clearWarnings()
        close()
        commit()
        createStatement()
        getAutoClose()
        getAutoCommit()
        getCatalog()
        getMetaData()
        getTransactionIsolation()
        getWarnings()
        isClosed()
        isReadOnly()
        nativeSql()
        prepareCall()
        prepareStatement()
        queryOdbcBridge()
        rollback()
        setAutoClose()
        setAutoCommit()
        setCatalog()
        setReadOnly()
        setTransactionIsolation()
      Class JdbcOdbcDatabaseMetaData
      Class JdbcOdbcDriver
        constructors
        acceptsURL()
        connect()
        getMajorVersion()
        getMinorVersion()
        getPropertyInfo()
        jdbcCompliant()
      Class JdbcOdbcPreparedStatement
        constructors
        clearParameter()
        execute()
        executeQuery()
        executeUpdate()
        set...()
        setNull()
        setObject()
        setAsciiStream()
        setBinaryStream()
        setUnicodeStream()
      Class JdbcOdbcResultSet
        constructors
        clearWarnings()
        close()
        findColumn()
        get...()
        getAsciiStream()
        getBinaryStream()
        getCursorName()
        getMetaData()
        getObject()
        getUnicodeStream()
        getWarnings()
        next()
        wasNull()
      Class JdbcOdbcResultSetMetaData
        definitions
        constructors
        getCatalogName()
        getColumnCount()
        getColumnDisplaySize()
        getColumnLabel()
        getColumnName()
        getColumnType()
        getColumnTypeName()
        getPrecision()
        getScale()
        getSchemaName()
        getTableName()
        isAutoIncrement()
        isCurrency()
        isCaseSensitive()
        isDefinitelyWritable()
        isNullable()
        isReadOnly()
        isSearchAble()
        isSigned()
        isWritable()
      Class JdbcOdbcStatement
        constructors
        cancel()
        clearWarnings()
        close()
        execute()
        executeQuery()
        executeUpdate()
        getCursorName()
        getMaxFieldSize()
        getMaxRows()
        getMoreResultSet()
        getQueryTimeout()
        getResultSet()
        getWarnings()
        getUpdateCount()
        setCursorName()
        setEscapeProcessing()
        setMaxFieldSize()
        setMaxRows()
        setQueryTimeout()
  Examples
    Example #1
    Example #2
  History
  Author's Details
  Archive Location

Jdbc-Odbc-Bridge V "1.00.6"


Info

JDBC-ODBC bridge for OS/2
* database access under Java *
All programs included in this package are provided "as is", without
any warranty! Try them on your own risk.

(c) 1996 by Dirk Ohme - all rights reserved

Note:
All files of the JDBC-ODBC bridge are copyrighted by Dirk Ohme. You are allowed to use them and all related stuff in non-commerical environments without any fee. If you want to use them within a commerical environment, please contact the author. The archive may be distributed freely, but only as one package that mustn't be modified to the original distribution!

Requirements

In order to do something useful, you need the following:

  • Java Development Kit V 1.0.2 or newer (is provided with IBM OS/2 4.0 Merlin, or see here)
  • Java DataBase Connectivity (JDBC), Driver Manager 1.10 or newer (also see here)
  • a database software with a ODBC driver available, for OS/2 the list contains:
  • IBM DB2/2 V 2.1
  • Solid Server 2.1
  • Mini SQL 1.0.16
  • Mini SQL 2.0
  • (any other software supported by iODBC for OS/2)

    Introduction

    Java, Sun's progressive new platform-independent language, is a first-level choice of todays software development. Because of its strength - to be platform independent - it fits the needs for having software on various (different) hardware.

    But a programming language is one thing - another the access to the peripherie, especially the access to data storages, as represented by SQL databases. In order to prevent proprietary solutions, Sunsoft, a daughter firm of Sun Systems, set up a standard for database access, called JDBC - Java DataBase Connection. This API is based on experiences of previous solutions for other languages and systems - mainly X/Open's SQL Call-Level Interface (CLI) and Microsoft's Open DataBase Connectivity (ODBC)..

    The main idea is as follows:

  • The Java application talks to a standarized API, represented by
  • the JDBC driver manager, that, depending on the connection parameters set by the application, connects to one of the
  • JDBC drivers. They implement methods and routines for accessing the data on a database. A JDBC driver may be either database specific, or represent a
  • JDBC-ODBC bridge, which translates JDBC requests to the appropriate ODBC calls. These are then sent to the
  • ODBC driver manager, that calls the proper
  • ODBC driver for database access.

    One may say, that using a JDBC-ODBC bridge reduces performance of a Java application. Sure, each call-translation cost time. On the other hand, there are not enough native Java JDBC drivers available, yet. A lot of database vendors don't develop or haven't developed yet JDBC drivers. So for many databases taking the ODBC driver is the only chance to get in connection with the data.

    1,2,3-Tier Solutions

    Speaking of Java DataBase Connection means speaking of connecting two different worlds. Most databases are written in an other language than Java, so interactions have to go across a border set up by the system(s). To build the bridge between application and database, there are several solutions depending the database system:

  • The so-called 1-tier solution represents a JDBC driver, that connects directly to the database system (i.e. to its proprietary protocol or API). Such solutions are rare, because informations about internal protocols and other details of databases are kept close by the manufacturer. A 1-tier driver is always written entirely in Java and is platform-independent.
  • Therefor 2-tier solutions use the official programming API or interface of the database. This includes the indirect going via ODBC driver manager and ODBC driver. Such a solutions consists of a JDBC driver written in Java, which calls routines located in an external dynamic runtime library (under Unix a dynamic library lib*.sl, under OS/2 or Windows a dynamic link library *.DLL), written mostly in C/C++. For that reason, 2-tier solutions are not platform-independent.
  • At last, the 3-tier solutions take another step. A JDBC driver, written entirely in Java, talks to a server process on the same or another machine (i.e. TCP/IP-connection). This server process is written in another language (C/C++, or anything else) and has the routines for database access built-in. Here, the Java application stays platform-independent, only the separate server process is platform dependent. But the server process may not be located on the same machine as the application - it may be moved to any machine the Java application may connect to. So the Java application can be a web applet, which is downloadable by any user in the Internet.

    For the moment, this JDBC-ODBC bridge is a 2-tier solution, so the Java applications needs its dynamic library on the same machine. A 3-tier solution may be available at a later time ...

    Further Informations ...

    For further informations have a look on the following links and references:

  • IBM Center for Java Technologie - http://ncc.hursley.ibm.com/javainfo
  • Java Home Page (Java, JDBC, JDBC driver manager) - http://java.sun.com

    Copyrights

    The Java(tm) technology is owned and exclusively licensed by Sun Microsystems Inc.. Java is a trademark of Sun Microsystems Inc. in the U.S. and other countries.

    Classes

    This chapter and the chapters below describe the Java classes available with the JDBC-ODBC bridge.

    The implementation of the JDBC-ODBC bridge consists of a layer of several classes. As mentioned before, the application communicates with an abstraction class, the JDBC driver manager. This one returns for each connection a proper link to a JDBC driver. When performing database interactions, a SQL statement has to be prepared, sent and a result gathered. For each task a Java class is set up.

    On this JDBC-ODBC bridge, there is another class J2ODBC implemented, which connects the JDBC part with the ODBC driver manager. As shown in the diagram, the various JDBC classes use the same J2ODBC class for interactions through the ODBC.

    Classes of the ODBC interface

    This section describes the classes and methods of the ODBC interface.

    Classes

  • class J2ODBC

    Exceptions

  • class J2ODBCException

    Warnings

  • class J2ODBCWarning

    class J2ODBC

    This class is implemented as package iODBC.sql.dll. Therefore an import should reference iODBC.sql.dll.J2ODBC (and iODBC.sql.dll.J2ODBCException for exception handling, too).

    The class requires an external link library,

  • called J2ODBC.DLL under OS/2, Win95 or WinNT,
  • called libJ2ODBC.so under Unix.

    constants

    Global definitions:

  • FALSE - representative for boolean SQL data type
  • TRUE - representative for boolean SQL data type

    SQL data types:

  • SQL_UNKNOWN and SQL_ALL_TYPES - representatives for unknown type and any type
  • SQL_DEFAULT - representative for default type
  • SQL_BINARY - binary data
  • SQL_BIT - binary/boolean value
  • SQL_BIT_VARYING - varying binary/boolean value
  • SQL_BLOB - binary large object (data)
  • SQL_BLOB_LOCATOR - binary large object locator
  • SQL_CLOB - character large object (data)
  • SQL_CLOB_LOCATOR - character large object locator
  • SQL_C_LONG - (long) integer number (equals long in C)
  • SQL_C_SHORT - (small) integer number (equals short in C)
  • SQL_CHAR - character(s), fixed allocated space in database
  • SQL_DATE - date representative
  • SQL_DATETIME - date/time representative
  • SQL_DBCHAR - database representation of character(s)
  • SQL_DBCLOB - database character large object (data)
  • SQL_DBCLOB_LOCATOR - database character large object locator
  • SQL_DECIMAL - decimal value
  • SQL_DOUBLE - floating point number (double precision)
  • SQL_FLOAT - floating pointer number (single precision)
  • SQL_GRAPHIC - some graphic data
  • SQL_INTEGER - integer number
  • SQL_INTERVAL - interval
  • SQL_LONGVARBINARY - large binary data block
  • SQL_LONGVARCHAR - large character data block
  • SQL_LONGVARGRAPHIC - large block containg graphic data
  • SQL_NUMERIC - (unspecified) numerical value
  • SQL_REAL - floating pointer number
  • SQL_SMALLINT - (small) integer number
  • SQL_TIME - time representative
  • SQL_TIMESTAMP - time stamp representative
  • SQL_TINYINT - small integer value
  • SQL_VARBINARY - binary data, variable allocated space in database
  • SQL_VARCHAR - characters, variable allocated space in database
  • SQL_VARGRAPHIC - graphic data, variable allocated space in database

    constructors

    public J2ODBC();
    public J2ODBC( J2ODBC currConnection );
    

    The first constructor creates a new, fresh object. The second can be used to create an object connected to a current object connected to a ODBC source. But instead of the cloning (as done by clone()), this constructor leaves the statement handle uninitialized.

    Note:
    By constructing a new object using an already open connection keep in mind, that there is only one connection path. So on exit, only one object must close the handles!

    allocConnect()

    public native void    allocConnect() throws Exception;
    

    Allocates a new connection handle. Must be called after allocEnv() in order to establish a connection via connect().

    To free a connection handle, use the freeEnv() method.

    allocEnv()

    public native void    allocEnv() throws Exception;
    

    Allocates a new environment for ODBC activities. Must be called before any other ODBC routine. To free the environment, use freeEnv().

    allocStmt()

    public native void    allocStmt() throws Exception;
    

    Before a SQL statement could be prepared or executed, a statement handle has to be obtained from the ODBC driver. This method provides an access to a new statement handle. In order to release the obtained handle, the freeStmt() method should be called.

    Note:
    In this implementation, each object of the class J2ODBC can obtain only one statement handle. If there is the need to have more than one handle open, a new object has to be created using the J2ODBC( currConnection ) constructor.

    bindCol()

    // public native void    bindCol();
    

    not implemented yet!

    browseConnect()

    public native String  browseConnect( String connStr ) throws Exception;
    

    Browse connStr and return a connection string.

    cancel()

    public native void    cancel() throws Exception;
    

    Cancels a long-time SQL statement/transaction.

    clone()

    public Object         clone();
    

    Returns a clone of the current object, i.e. a new object, pointing to the same ODBC data source with a copy of the current statement handle.

    Note:
    By constructing a new object using an already open connection keep in mind, that there is only one connection path. So on exit, only one object must close the handles!

    collAttributes...()

    public native void    colAttributes( int colIndex,
                                         int fDescType ) throws Exception;
    public String         colAttributesString() { return attrDesc; }
    public int            colAttributesValue() { return attrValue; }
    

    Returns the value for a specified attribute fDescType for a column (1 <= colIndex <= numResultCols()).

    For string results, colAttributesString() returns the result; for numerical results, colAttributesValue() returns the result.

    Possible values for fDescType are:
    name STR VAL description
    COLUMN_AUTO_INCREMENT * boolean value, TRUE = column value automatically increments on insertion (auto primary key)
    COLUMN_CASE_SENSITIVE * boolean value, TRUE = column contains case-sensitive data (like characters)
    COLUMN_CATALOG_NAME * name of the catalog containing the table
    COLUMN_COUNT * number of resulting columns (colIndex is unused)
    COLUMN_DISPLAY_SIZE * size need for display data (characters)
    COLUMN_LABEL * label of the column name, or, if un-labeled, the column name
    COLUMN_LENGTH * length of column in characters
    COLUMN_MONEY * boolean value, TRUE = column represent a currency
    COLUMN_NAME * name of the column in result set
    COLUMN_NULLABLE * boolean value, TRUE = column can be set NULL
    COLUMN_OWNER_NAME * name of the table owner
    COLUMN_PRECISION * precision (on number columns)
    COLUMN_QUALIFIER_NAME * name of the database containing the table
    COLUMN_SCALE * scaling (on number columns)
    COLUMN_SCHEMA_NAME * name of the schema containing the table
    COLUMN_SEARCHABLE * (see below)
    COLUMN_TABLE_NAME * name of the database table containing the column specified
    COLUMN_TYPE * SQL data type, see 'constants' for possible values
    COLUMN_TYPE_NAME * name of the SQL data type used in that column
    COLUMN_UNSIGNED * boolean value, TRUE = column contains unsigned data (number)
    COLUMN_UPDATABLE * (see below)

    Possible returns for COLUMN_UPDATABLE:

  • ATTR_READONLY = column cannot be updated (is read-only)
  • ATTR_WRITE = column is updatable
  • ATTR_READWRITE_UNKNOWN = column may be updatable

    Possible returns for COLUMN_SEARCHABLE:

  • UNSEARCHABLE = column value cannot be searched within the WHERE clause of a SQL statement
  • LIKE_ONLY = column value can only be searched by a LIKE in a WHERE clause
  • ALL_EXCEPT_LIKE = column value can be searched within a WHERE clause, except in condition with LIKE
  • SEARCHABLE = column value can be searched without exception

    columns()

    public native void    columns( String tableQualifier,
                                   String tableOwner,
                                   String tableName,
                                   String columnName ) throws Exception;
    

    Returns the columns matching the conditions in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. The parameter tableQualifier, if set, reduces the resulting list to those tables, which are mapped to the specified qualifier (catalogue). The same do tableOwner for the owner of tables, tableName for table names and columnName for the name of columns. Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    connect()

    public native void    connect( String dsn,
                                   String uid,
                                   String pwd ) throws Exception;
    

    Connects to a given ODBC data source dsn using the user name uid and password pwd. This call has to be executed before any database interactions. Previously the environment and the database context have to be initialized (see allocEnv and allocConnect).

    In order to withdraw from a database, use disconnect().

    describeCol...()

    public native void    describeCol( int colIndex ) throws Exception;
    public String         describeColName() { return colName; }
    public int            describeColType() { return colSqlType; }
    public int            describeColPrecision() { return colPrecision; }
    public int            describeColScale() { return colScale; }
    public boolean        describeColNullable() { return colNullable; }
    

    The describeCol() method gets the information about a column colIndex of a result set of a query, which can be gathered by the other methods:

  • describeColName() returns the name of the column
  • describeColType() returns the type of the column (see 'constants')
  • describeColPrecision() returns the precision of the column
  • describeColScale() returns the scale of the column
  • describeColNullable() returns whether a column can store a NULL value or not

    describeParam...()

    public native void    describeParam( int paramIndex ) throws Exception;
    public int            describeParamType() { return colSqlType; }
    public int            describeParamPrecision() { return colPrecision; }
    public int            describeParamScale() { return colScale; }
    public boolean        describeParamNullable() { return colNullable; }
    

    The describeParam() method gets the information about parameter no. colIndex of a SQL preparedstatement, which can be gathered by the other methods:

  • describeParamType() returns the type of the parameter (see 'constants')
  • describeParamPrecision() returns the precision of the parameter
  • describeParamScale() returns the scale of the parameter
  • describeParamNullable() returns whether a parameter can store a NULL value or not

    disconnect()

    public native void    disconnect() throws Exception;
    

    Closes a connection opened by a connect() or driverConnect() call.

    driverConnect()

    public native String  driverConnect( String connStr,
                                         int fDrvCmpl ) throws Exception;
    

    Like connect() this routine allows connection to a ODBC data source. But unlike the other routine, a connection string (connStr) has to be defined, which consists of these entries:

  • DSN=data_source_name - name of the data source to connect to
  • UID=user_name - user name used during connection
  • PWD=password - password used during connection

    The entries are separated by colons (;). Further, a flag fDrvCmpl can be specified, which tells the ODBC driver whether and how to prompt (login dialog window) for missing data necessary during login, or not. The available flags are:

  • DRIVER_NOPROMPT - do not prompt for missing data, try to connect with the given data
  • DRIVER_COMPLETE - prompt for missing data, necessary for login
  • DRIVER_PROMPT - always prompt, display all data
  • DRIVER_COMPLETE_REQUIRED - only prompt for missing data, that is mandatory

    In order to withdraw from a database, use disconnect().

    error()

    public native String  error() throws Exception;
    

    Returns a string representation for a previously occurred database or ODBC error.

    execDirect()

    public native void    execDirect( String sqlStmt ) throws Exception;
    

    Prepares and then executes a given SQL statement sqlStmt. On DELETE, INSERT or UPDATE rowCount() returns the number of rows affected, on queries numResultCols() returns the number of columns in the result set (see fetch()).

    execute()

    public native void    execute() throws Exception;
    

    Executes a previously prepared SQL statement. On DELETE, INSERT or UPDATE rowCount() returns the number of rows affected, on queries numResultCols() returns the number of columns in the result set (see fetch()).

    extendedFetch()

    // public native boolean extendedFetch();
    

    Not implemented yet!

    See fetch() instead.

    fetch()

    public native boolean fetch() throws Exception;
    

    Loads the first/next row of the result set of a query so it can be accessed by getData...() calls.

    foreignKeys()

    public native void    foreignKeys( String pkTableQualifier,
                                       String pkTableOwner,
                                       String pkTableName,
                                       String fkTableQualifier,
                                       String fkTableOwner,
                                       String fkTableName ) throws Exception;
    

    Returns the foreign-primary key relation on tables matching the conditions in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. pkTableQualifier specifies a search criteria on qualifiers (catalogues) of primary keys, fkTableQualifier on qualifiers of foreign keys of tables. pkTableOwner (fkTableOwner) defines a search criteria on owners of primary keys (foreign keys), pkTableName (fkTableName) a criteria on table names with primary (foreign) keys. Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    freeConnect()

    public native void    freeConnect() throws Exception;
    

    Frees a database context allocated by allocConnect(). This can only be done, if all previous transactions have been completed (see transact()). Afterwards the environment can be freed via the freeEnv() routine.

    freeEnv()

    public native void    freeEnv() throws Exception;
    

    Frees an environment allocated by allocEnv(). Freeing the environment is the last step after all database interactions, in order to terminate properly. Previous, all database contexts have to be freed by freeConnect() calls.

    freeStmt()

    public native void    freeStmt( int fOption ) throws Exception;
    

    Frees or manipulates a statement handle allocated by the allocStmt() method. fOption may be one of this:

  • CLOSE - closes the current statement handle, but keeps the resource so that another SQL statement can be executed (see prepare(), execute() and execDirect()).
  • DROP - closes the current statement handle and drops the resources
  • UNBIND - keeps the statement handle, but frees the variables previously bound to columns by the bindCol() method.
  • RESET_PARAMS - keeps the statement handle, but frees the parameter variables previously bound by the setParam() method.

    getConnectOption...()

    public native int     getConnectOptionNum( int fOption ) throws Exception;
    public native String  getConnectOptionStr( int fOption ) throws Exception;
    

    Returns informations about a connection. fOption specifies the type of information to be returned:
    name NUM STR description
    ACCESS_MODE * access mode to database source, see below
    AUTOCOMMIT * automatical COMMIT on the end of a session, see below
    CURRENT_QUALIFIER * current qualifier name
    LOGIN_TIMEOUT * timeout value on login, LOGIN_TIMEOUT_DEFAULT specifies the default setting
    ODBC_CURSORS * type of cursors, see below
    OPT_TRACE * trace mode setting, see below
    OPT_TRACEFILE * name of the trace file, when tracing is enabled - OPT_TRACE_FILE_DEFAULT specifies the default file name
    QUIET_MODE * application window handle under which dialog boxes are placed as childs
    PACKET_SIZE * transfer packets size
    TRANSLATE_DLL * name of the translation DLL
    TRANSLATE_OPTION * translation option
    TXN_ISOLATION * transaction isolation level, TRUE, if transactions are isolated

    Options possible for ACCESS_MODE:

  • MODE_READ_WRITE - read/write access to database source
  • MODE_READ_ONLY - read-only access to database source
  • MODE_DEFAULT - use default setting

    Options possible for AUTOCOMMIT:

  • AUTOCOMMIT_OFF - prevent automatical COMMIT
  • AUTOCOMMIT_ON - enable automatical COMMIT
  • AUTOCOMMIT_DEFAULT - use default setting

    Options possible for ODBC_CURSORS:

  • CUR_USE_IF_NEEDED - use cursors only if needed
  • CUR_USE_ODBC - use ODBC cursors
  • CUR_USE_DRIVER - use cursors provided with the driver
  • CUR_DEFAULT - use default setting

    Options possible for OPT_TRACE:

  • OPT_TRACE_OFF - tracing disabled
  • OPT_TRACE_ON_ - tracing enabled
  • OPT_TRACE_DEFAULT - use default setting

    getCursorName()

    public native String  getCursorName() throws Exception;
    

    Returns the name of the cursor associated with the currently processed statement.

    getData...()

    public boolean        getDataCheckForNull() { return colIsNull; }
    public native boolean getDataBoolean( int colIndex ) throws Exception;
    // public native Date  getDataDate( int colIndex ) throws Exception;
    public native double  getDataDouble( int colIndex ) throws Exception;
    public native float   getDataFloat( int colIndex ) throws Exception;
    public native int     getDataInteger( int colIndex ) throws Exception;
    public native String  getDataString( int colIndex ) throws Exception;
    

    Returns the contents of a column (with 1 <= colIndex <= numResultCols()) in the requested data type.

    getDataDate() is not implemented yet!

    getDataCheckForNull() returns true if the last column requested contains a SQL NULL value.

    Before the first access to a column of the resulting set and before the access to the next row, a fetch() call has to be done.

    getInfoNum(), getInfoStr()

    public native int     getInfoNum( int fInfoType ) throws Exception;
    public native String  getInfoStr( int fInfoType ) throws Exception;
    

    These calls can be used to retrieve informations about the ODBC sub-system. Because some informations are represented by number, some by strings, there are two methods for accessing them. The following list shows the possible request flags (fInfoType):
    name NUM STR description
    CURSOR_COMMIT_BEHAVIOR * describes the reaction of open cursors to COMMIT (see below).
    CURSOR_ROLLBACK_BEHAVIOR * describes the reaction of open cursors to ROLLBACK (see below).
    DEFAULT_TXN_ISOLATION * returns a mask describing the default transaction isolation level (see below).
    DRIVER_HDBC * returns the currently used database context handle
    DRIVER_HENV * returns the currently used environment handle
    DRIVER_HLIB * returns the currently used library handle
    DRIVER_HSTMT * returns the currently used statement handle
    DRIVER_NAME * returns the name of the ODBC driver used
    DRIVER_ODBC_VER * returns the version of the ODBC driver as string (like '2.1')
    NON_NULLABLE_COLUMNS * returns in a boolean value whether table columns can be set equal NULL or not.
    ODBC_VER * returns the version string for the ODBC driver (like '02.01')
    QUALIFIER_LOCATION * returns the location of the qualifier in a qualified table name
    TXN_ISOLATION_OPTION * returns the transaction isolation levels available at the current connection (see below).

    Options for CURSOR_COMMIT_BEHAVIOUR and CURSOR_ROLLBACK_BEHAVIOUR:

    Options for DEFAULT_TXN_ISOLATION and TXN_ISOLATION_OPTION:

    getStmtOption...()

    public native int     getStmtOptionNum( int fOption ) throws Exception;
    public native String  getStmtOptionStr( int fOption ) throws Exception;
    

    Returns informations about a statement handle. Possible values for fOption are:
    name Num Str description
    ASYNC_ENABLE * returns TRUE when SQL statements are executed asynchronously
    BIND_TYPE * returns the binding type
    CONCURRENCY * returns cursor concurrencies, see below.
    CURSOR_TYPE * returns the cursor type on the statement handle
    GET_BOOKMARK not supported!
    KEYSET_SIZE * returns the size of the key set
    MAX_LENGTH * 0 or the maximum length of a result column of a query
    MAX_ROWS * returns the maximum number of rows produced by the last query executed
    NOSCAN * returns TRUE if there is no scan for escape sequences in SQL statements
    QUERY_TIMEOUT * returns the timeout value on queries
    RETRIEVE_DATA not supported!
    ROW_NUMBER not supported!
    ROWSET_SIZE * returns the size of the row set
    SIMULATE_CURSOR not supported!
    USE_BOOKMARKS not supported!

    Possible values for CONCURRENCY:

  • CONCUR_READ_ONLY - cursor is read-only, no updates allowed
  • CONCUR_LOCK - update allowed using locking mechanism
  • CONCUR_ROWVER - update allowed using row version method
  • CONCUR_VALUES - update allowed

    getTypeInfo()

    public native void    getTypeInfo( int fSqlType ) throws Exception;
    

    Returns a result set (like a query does), describing details about the given SQL data type (fSqlType). See 'constants' for a description of valid SQL data types.

    moreResults()

    public native boolean moreResults() throws Exception;
    

    Checks for further result sets and initializes them.

    nativeSql()

    public native String  nativeSql( String sqlStmt ) throws Exception;
    

    Translates a given SQL statement sqlStmt, containing database specific extensions, into a native SQL statement.

    numParams()

    public native int     numParams() throws Exception;
    

    Returns the number of parameter markers set in a SQL statement, which has been prepared.

    numResultCols()

    public native int     numResultCols() throws Exception;
    

    Returns the number of columns available in a result set of a query. This method may be called after a prepare() or a execDirect() call.

    paramData()

    // public native void    paramData();
    

    not implemented yet!

    paramOptions...()

    public native void    paramOptions( int numOfParams ) throws Exception;
    public int            paramOptionsResultNumber() { return paramResultNumber; }
    

    Allows the setting of various parameter arrays in combination with setParam(). numOfParams specifies, how many entries in the array exists for one parameter. The result of the paramOptions()-call can be gathered by the paramOptionsResultNumber-routine, which returns the number of array indices successfully processed.

    prepare()

    public native void    prepare( String sqlStmt ) throws Exception;
    

    Before execution of a SQL statement (sqlStmt) it has to be prepared. This method causes the SQL engine to prepare the given statement for execution, that can be then done by the execute() method.

    Another way for direct execution is the execDirect() method, which combines preparation and execution state.

    primaryKeys()

    public native void    primaryKeys( String tableQualifier,
                                       String tableOwner,
                                       String tableName ) throws Exception;
    

    Returns the primary keys of tables matching the conditions in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. The parameter tableQualifier, if set, reduces the resulting list to those tables, which are mapped to the specified qualifier (catalogue). The same do tableOwner for the owner of tables and tableName for table names. Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    procedures()

    public native void    procedures( String procQualifier,
                                      String procOwner,
                                      String procName ) throws Exception;
    

    This method returns names and other data of stored database procedures in a result set, like a query does. procQualifier specifies a search criteria on qualifiers (catalogues), procOwner on owners of such procedures, and procName on procedure names. Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    procedureColumns()

    public native void    procedureColumns( String procQualifier,
                                            String procOwner,
                                            String procName,
                                            String columnName ) throws Exception;
    

    This method returns data about parameters of stored database procedures in a result set, like a query does. procQualifier specifies a search criteria on qualifiers (catalogues), procOwner on owners of such procedures, procName on procedure names, and columnName on column (i.e. parameters). Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    putData()

    // public native void    putData();
    

    not implemented yet!

    rowCount()

    public native int     rowCount() throws Exception;
    

    Returns the number of rows affected by an DELETE, INSERT or UPDATE statement executed via execute() or execDirect().

    setConnectOption...()

    public native void    setConnectOptionNum( int fOption,
                                               int paramValue ) throws Exception;
    public native void    setConnectOptionStr( int fOption,
                                               String paramStr ) throws Exception;
    

    Sets options on a connection. fOption specifies the type of option to be set, which is done by the paramValue or paramStr parameter. Possible values for fOption are:
    name NUM STR description
    ACCESS_MODE * access mode to database source, see below
    AUTOCOMMIT * automatical COMMIT on the end of a session, see below
    CURRENT_QUALIFIER * current qualifier name
    LOGIN_TIMEOUT * timeout value on login, LOGIN_TIMEOUT_DEFAULT specifies the default setting
    ODBC_CURSORS * type of cursors, see below
    OPT_TRACE * trace mode setting, see below
    OPT_TRACEFILE * name of the trace file, when tracing is enabled - OPT_TRACE_FILE_DEFAULT specifies the default file name
    QUIET_MODE * application window handle under which dialog boxes are placed as childs
    PACKET_SIZE * transfer packets size
    TRANSLATE_DLL * name of the translation DLL
    TRANSLATE_OPTION * translation option
    TXN_ISOLATION * transaction isolation level, TRUE, if transactions are isolated

    Options possible for ACCESS_MODE:

  • MODE_READ_WRITE - read/write access to database source
  • MODE_READ_ONLY - read-only access to database source
  • MODE_DEFAULT - use default setting

    Options possible for AUTOCOMMIT:

  • AUTOCOMMIT_OFF - prevent automatical COMMIT
  • AUTOCOMMIT_ON - enable automatical COMMIT
  • AUTOCOMMIT_DEFAULT - use default setting

    Options possible for ODBC_CURSORS:

  • CUR_USE_IF_NEEDED - use cursors only if needed
  • CUR_USE_ODBC - use ODBC cursors
  • CUR_USE_DRIVER - use cursors provided with the driver
  • CUR_DEFAULT - use default setting

    Options possible for OPT_TRACE:

  • OPT_TRACE_OFF - tracing disabled
  • OPT_TRACE_ON_ - tracing enabled
  • OPT_TRACE_DEFAULT - use default setting

    setCursorName()

    public native void    setCursorName( String cursorName ) throws Exception;
    

    Sets the name of the cursor associated with the currently processed statement to cursorName

    setParam()

    // public native void    setParam();
    

    not implemented yet!

    setPos()

    public native void    setPos( int rowIndex,
                                  boolean fRefresh,
                                  boolean fLock ) throws Exception;
    

    Sets a cursor to a specific row rowIndex in the result set. Boolean values describe whether to update the result set (fRefresh) and/or to lock the result set (fLock), or not.

    setScrollOptions()

    public native void    setScrollOptions( int fConcurrency,
                                            int crowKeyset,
                                            int crowRowset ) throws Exception;
    

    Set scolling options.

    setStmtOption...()

    public native void    setStmtOptionNum( int fOption,
                                            int paramValue ) throws Exception;
    public native void    setStmtOptionStr( int fOption,
                                            String paramStr ) throws Exception;
    

    Sets options on a statement handle. paramValue and paramStr are the values to be set, and fOption is the option reference. Possible values for fOption are:
    name Num Str description
    ASYNC_ENABLE * when set TRUE, SQL statements are executed asynchronously
    BIND_TYPE * sets the binding type
    CONCURRENCY * sets cursor concurrencies, see below.
    CURSOR_TYPE * sets the cursor type on the statement handle
    GET_BOOKMARK not supported!
    KEYSET_SIZE * sets the size of the key set
    MAX_LENGTH * sets the maximum length of a result column of a query, use MAX_LENGTH_DEFAULT for no limit
    MAX_ROWS * sets the maximum number of rows producable by a query, use MAX_ROWS_DEFAULT for no limit
    NOSCAN * when set TRUE, there is no scan for escape sequences in SQL statements
    QUERY_TIMEOUT * sets the timeout value on queries, use QUERY_TIMEOUT_DEFAULT for no limit
    RETRIEVE_DATA not supported!
    ROW_NUMBER not supported!
    ROWSET_SIZE * sets the size of the row set
    SIMULATE_CURSOR not supported!
    USE_BOOKMARKS not supported!

    Possible values for CONCURRENCY:

  • CONCUR_READ_ONLY - cursor is read-only, no updates allowed
  • CONCUR_LOCK - update allowed using locking mechanism
  • CONCUR_ROWVER - update allowed using row version method
  • CONCUR_VALUES - update allowed

    specialColumns()

    public native void    specialColumns( int fColType,
                                          String tableQualifier,
                                          String tableOwner,
                                          String tableName,
                                          int fScope,
                                          boolean fNullable ) throws Exception;
    

    Returns special columns (like primary keys or indices) of tables matching the conditions in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. fColType is one of these:

  • BEST_ROWID - return the best set of column(s) for identification of a row
  • ROWVER - return all data (?) The parameter tableQualifier, if set, reduces the resulting list to those tables, which are mapped to the specified qualifier (catalogue). The same do tableOwner for the owner of tables and tableName for table names. Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters. The parameter fScope specifies the duration, on which a ROWID value identifying a single row is valid:

  • SCOPE_CURROW - only for the next statement
  • SCOPE_TRANSACTION - during this transaction
  • SCOPE_SESSION - during this connection

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    statistics()

    public native void    statistics( String tableQualifier,
                                      String tableOwner,
                                      String tableName,
                                      boolean fUnique,
                                      boolean fAccuracy ) throws Exception;
    

    Returns statistics about one or more tables matching the search criterias in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. The parameter tableQualifier, if set, reduces the resulting list to those tables, which are mapped to the specified qualifier (catalogue). The same do tableOwner for the owner of tables and tableName for table names. Setting a parameter null disables this search criteria and returns all data (matching the other criterias). The parameter fUnique (if set TRUE) prevents redundancies in data about indices, the parameter fAccuracy (if set TRUE) ensures data returned to be stable - under some conditions setting this may be necessary to prevent inaccurate data.

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    tablePrivileges()

    public native void    tablePrivileges( String tableQualifier,
                                           String tableOwner,
                                           String tableName ) throws Exception;
    

    Returns privileges on tables matching the conditions in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. The parameter tableQualifier, if set, reduces the resulting list to those tables, which are mapped to the specified qualifier (catalogue). The same do tableOwner for the owner of tables and tableName for table names. Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    tables()

    public native void    tables( String tableQualifier,
                                  String tableOwner,
                                  String tableName,
                                  String tableType ) throws Exception;
    

    Returns the tables matching the conditions in a result set, like a query does. Before this method can be called, a statement handle has to be obtained. The parameter tableQualifier, if set, reduces the resulting list to those tables, which are mapped to the specified qualifier (catalogue). The same do tableOwner for the owner of tables, tableName for table names and tableType for the type of table (i.e. views, real tables, aliases, synonyms, etc.). Setting a parameter null disables this search criteria and returns all data (matching the other criterias).

    In some string parameters a so-called joker ('%') may occur. It stands for a variable-sized string of variable characters.

    Note:
    The result may vary depending on the database software (i.e. ODBC driver). Consult the appropriate documentation there!

    transact()

    public native void    transact( int fType ) throws Exception;
    

    Terminates all previous database transactions be validating (fType = COMMIT) or invalidating (ROLLBACK) them.

    class J2ODBCException

    The exception class used within class iODBC.sql.dll.J2ODBC.

    constructors

    public J2ODBCException();
    public J2ODBCException( String reason );
    public J2ODBCException( String reason, String SQLState );
    public J2ODBCException( String reason, String SQLState, int vendorCode );
    

    The first constructor may be used to create an empty exception, the second sets a exception containing the specified message. The third may be used to specify a certain SQL state and the last even to specify a vendor specific code.

    class J2ODBCWarning

    The warning class used within class iODBC.sql.dll.J2ODBC.

    constructors

    public J2ODBCWarning();
    public J2ODBCWarning( String reason );
    public J2ODBCWarning( String reason, String SQLState );
    public J2ODBCWarning( String reason, String SQLState, int vendorCode );
    

    The first constructor may be used to create an empty exception, the second sets a exception containing the specified message. The third may be used to specify a certain SQL state and the last even to specify a vendor specific code.

    Classes of the JDBC interface

    This chapter and all chapters below describe the Java classes available with the JDBC interface.

    Classes

  • class JdbcOdbcCallableStatement
  • class JdbcOdbcConnection
  • class JdbcOdbcDatabaseMetaData
  • class JdbcOdbcDriver
  • class JdbcOdbcPreparedStatement
  • class JdbcOdbcResultSet
  • class JdbcOdbcResultSetMetaData
  • class JdbcOdbcStatement

    Exceptions

    Class JdbcOdbcCallableStatement

    This class provides access to SQL stored procedures. There are two different syntax schemes for functions and procedures:

  • ? = call <procedure name>[<arg1>,<arg2>,...]
  • call <procedure name>[<arg1>,<arg2>,...]

    The first scheme provides a result paramater, which has to be registered as an OUT parameter (see below). All parameters are refered sequentially by index numbers, starting with 1.

    So-called IN parameters, that are parameters filled before running the stored procedure, have to be set using the JdbcOdbcPreparedStatement::set...() methods. So-called OUT parameters, that are parameters filled by the stored procedure, have to be registers before execution of the stored procedure using registerOutParameter(). Afterwards, the results may be queried by the get...() methods.

    Callable statements may return zero, one or more result sets (see JdbcOdbcResultSet).

    constructors

    public JdbcOdbcCallableStatement( Connection dbConnection,
                                      J2ODBC odbcObj,
                                      String sql ) throws SQLException;
    

    Used by JdbcOdbcConnection::prepareCall() to create a new object. dbConnection refers to the current database connection, which uses the odbcObj ODBC interface. The call for the SQL stored procedure is given in sql.

    get...()

    public boolean getBoolean( int parameterIndex ) throws SQLException;
    public byte getByte( int parameterIndex ) throws SQLException:
    public byte[] getBytes( int parameterIndex ) throws SQLException;
    public java.sql.Date getDate( int parameterIndex ) throws SQLException;
    public double getDouble( int parameterIndex ) throws SQLException;
    public float getFloat( int parameterIndex ) throws SQLException;
    public int getInt( int parameterIndex ) throws SQLException;
    public long getLong( int parameterIndex ) throws SQLException;
    public Bignum getBignum( int parameterIndex, int scale ) throws SQLException;
    public Object getObject( int parameterIndex ) throws SQLException;
    public short getShort( int parameterIndex ) throws SQLException;
    public String getString( int parameterIndex ) throws SQLException;
    public java.sql.Time getTime( int parameterIndex ) throws SQLException;
    public java.sql.Timestamp getTimestamp( int parameterIndex )
            throws SQLException;
    

    Returns the contents of the parameter with index number parameterIndex (starting with 1) in the appropriate format. The following table shows which methods matches SQL data types very closely - on some databases it may be possible to specify a completely other SQL data type for a column/parameter, like CHAR for BIT.
    method SQL data type(s)
    getBoolean() BIT
    getByte() TINYINT
    getBytes() BINARY, VARBINARY
    getDate() DATE
    getDouble() DOUBLE
    getFloat() FLOAT
    getInt() INTEGER
    getLong() BIGINT
    getBignum() NUMERIC
    getObject() any data type (see below)
    getShort() SMALLINT
    getString() CHAR, VARCHAR, LONGVARCHAR
    getTime() TIME
    getTimestamp() TIMESTAMP

    Note:
    getObject() returns an object for a SQL data type, which has been previously set by
    registerOutParameter(). It may also be used to handle non-ODBC conformant data types or database vendor specific data type extension.

    registerOutParameter()

    public void registerOutParameter( int parameterIndex, int sqlType )
            throws SQLException;
    public void registerOutParameter( int parameterIndex, int sqlType, int scale )
            throws SQLException;
    

    Registers an OUT parameter in a call for a SQL stored procedure. parameterIndex contains the index number (starting with 1) of the parameter, sqlType the SQL data type (see java.sql.Type for details) and the additional parameter scale a scaling factor.

    wasNull()

    public boolean wasNull() throws SQLException;
    

    Returns true if the last parameter queried by a get...() method was NULL.

    Class JdbcOdbcConnection

    In order to perform database interactions, a connection has to be established. This class is the main part on database interactions. From within there could be statements prepared and executed, and result sets gathered.

    definitions

    The following definitions are available for getTransactionIsolation() and setTransactionIsolation():

  • TRANSACTION_NONE - transactions are not supported
  • TRANSACTION_READ_UNCOMMITTED - dirty reads are done
  • TRANSACTION_READ_COMMITTED - only reads on the current row are repeatable
  • TRANSACTION_REPEATABLE_READ - reads on all rows of a result are repeatable
  • TRANSACTION_SERIALIZEABLE - reads on all rows of a transaction are repeatable

    constructors

    public JdbcOdbcConnection( String user, String passwd, String db )
            throws SQLException;
    

    Used by the JdbcOdbcDriver class to perform a database login on database source db, using user name user and password passwd.

    destructors

    public void finalize() throws SQLException;
    

    On garbage collection this method is used to close the database connection. See close(), too.

    clearWarnings()

    public void clearWarnings() throws SQLException;
    

    Clears the last warning occurred from the message queue. See getWarnings(), too.

    close()

    public void close() throws SQLException;
    

    In order to close a connection directly without waiting for the garbage collection, this method may be called. After successful termination, no further actions can be done by this object - the next step should be the invalidation of the object reference (setting the variable null).

    commit()

    public void commit() throws SQLException;
    

    Validates all previous transactions, i.e. all changes done are saved. See rollback(), too.

    createStatement()

    public Statement createStatement() throws SQLException;
    

    Get a new object, which can obtain a SQL statement. See the JdbcOdbcStatement class for more details.

    getAutoClose()

    public boolean getAutoClose() throws SQLException;
    

    Returns the state of the 'automatic close of cursors on termination' mechanism. See setAutoClose(), too.

    getAutoCommit()

    public boolean getAutoCommit() throws SQLException;
    

    Returns the state of the AUTOCOMMIT feature. See setAutoCommit(), too.

    getCatalog()

    public String getCatalog() throws SQLException;
    

    Returns the catalogue name used in the transactions. This is normally the name of the database or data source used during login. See setCatalog(), too.

    getMetaData()

    public DatabaseMetaData getMetaData() throws SQLException;
    

    Returns an object which can be used to examine the database. See JdbcOdbcDatabaseMetaData for details.

    getTransactionIsolation()

    public int setTransactionIsolation() throws SQLException;
    

    Returns the current transaction isolation level. The result may be one of these constants:

  • TRANSACTION_NONE - transactions are not supported
  • TRANSACTION_READ_UNCOMMITTED - dirty reads are done
  • TRANSACTION_READ_COMMITTED - only reads on the current row are repeatable
  • TRANSACTION_REPEATABLE_READ - reads on all rows of a result are repeatable
  • TRANSACTION_SERIALIZEABLE - reads on all rows of a transaction are repeatable

    getWarnings()

    public SQLWarning getWarnings() throws SQLException;
    

    Returns the last warning occurred. See clearWarnings(), too.

    isClosed()

    public boolean isClosed() throws SQLException;
    

    Returns true if no connection exists.

    isReadOnly()

    public boolean isReadOnly() throws SQLException;
    

    Returns the state of a connection - true, if the connection is set read-only. See setReadOnly(), too.

    nativeSql()

    public String nativeSQL( String sql ) throws SQLException;
    

    A SQL statement (sql) may contain JDBC or ODBC specific escape sequences. This method provides a function for resolving such escape sequences. It returns native SQL syntax.

    prepareCall()

    public CallableStatement prepareCall( String sql ) throws SQLException;
    

    Get a new object, which obtains a SQL stored procedure call. The call sequence is set by the sql parameter. See the JdbcOdbcCallableStatement class for more details.

    prepareStatement()

    public PreparedStatement prepareStatement( String sql ) throws SQLException;
    

    Get a new object, which obtains a prepared SQL statement, formed by the SQL statement sql. See the JdbcOdbcPreparedStatement class for more details.

    queryOdbcBridge()

    public J2ODBC queryOdbcBridge() throws J2ODBCException;
    

    Returns the handle to the J2ODBC class, which is used for accessing the ODBC driver manager.

    rollback()

    public void rollback() throws SQLException;
    

    Invalidates all previous transactions, i.e. all changes done are withdrawn. See commit(), too.

    setAutoClose()

    public void setAutoClose( boolean autoClose ) throws SQLException;
    

    Enables or disables (autoClose equals true or false) the automatic close of cursors on termination. See getAutoClose(), too.

    setAutoCommit()

    public void setAutoCommit( boolean autoCommit ) throws SQLException;
    

    Enables or disables (depending on autoCommit) the AUTOCOMMIT feature provided with many databases. If enabled, on exit a database COMMIT is executed automatically. See getAutoCommit(), too.

    setCatalog()

    public void setCatalog( String catalog ) throws SQLException;
    

    Sets a new catalogue catalog for all following transactions. See getCatalog(), too.

    Note:
    On the JDBC-ODBC bridge, this method does not have any effect.

    setReadOnly()

    public void setReadOnly( boolean readOnly ) throws SQLException;
    

    Switches a connection to read-only, if readOnly is set true. See isReadOnly(), too.

    setTransactionIsolation()

    public void setTransactionIsolation( int level ) throws SQLException;
    

    Sets a new transaction isolation level. For level, these definitions are valid:

  • TRANSACTION_NONE - transactions are not supported
  • TRANSACTION_READ_UNCOMMITTED - dirty reads are done
  • TRANSACTION_READ_COMMITTED - only reads on the current row are repeatable
  • TRANSACTION_REPEATABLE_READ - reads on all rows of a result are repeatable
  • TRANSACTION_SERIALIZEABLE - reads on all rows of a transaction are repeatable

    Class JdbcOdbcDatabaseMetaData

    not implemented yet!

    Class JdbcOdbcDriver

    This class implements the base on which the other classes of the JDBC-ODBC bridge refer to. In order to access the JDBC-ODBC bridge, the JDBC driver manager has to be notified to use it. One way is to do so is to create an empty object of this class:

            new iODBC.sql.JdbcOdbcDriver();
    

    constructors

    public JdbcOdbcDriver() throws SQLException;
    

    Registers the JDBC-ODBC bridge at the JDBC driver manager. A following DriverManager::getConnection() call may then return an object to the bridge.

    acceptsURL()

    public boolean acceptsURL( String url ) throws SQLException;
    

    Returns true if the given uniform resource locator url can be resolved by this driver. On the JDBC-ODBC bridge such URLs has to start with jdbc:odbc: or jdbc:iodbc: in order to be resolved.

    connect()

    public Connection connect( String url, java.util.Properties info )
            throws SQLException;
    

    This method is normally called by the JDBC driver manager in order to perform a login to a given database or data source. url is a string identifying the data source; it is of the form jdbc:type:sub_type.

  • jdbc - is a fixed prefix
  • type - specifies the type of JDBC driver to be used; the JDBC-ODBC bridge registers the type odbc and iodbc
  • sub_type - a JDBC driver may distinguish between sub-types or may require additional parameters. The JDBC-ODBC bridge expects the name of the ODBC source as sub_type parameter

    Note:
    For connecting to the ODBC source test via JDBC-ODBC bridge, use the url = jdbc:odbc:test.

    info is a list of properties necessary during login. Currently the following properties are used:

  • user - user ID for database login
  • password - password for database login

    getMajorVersion()

    public int getMajorVersion();
    

    Returns the major version number of the driver.

    getMinorVersion()

    public int getMinorVersion();
    

    Returns the minor version number of the driver.

    getPropertyInfo()

    public DriverPropertyInfo[] getPropertyInfo( String url,
                                                 java.util.Properties info
                                               ) throws SQLException;
    

    Returns a list of required properties necessary for database login for the given url and property list info.

    jdbcCompliant()

    public boolean jdbcCompliant();
    

    Returns whether the driver is JDBC compliant or not. A result value of true reflects that the driver has been proved for

  • full support of the JDBC API
  • full support of the SQL 92 Entry level

    Class JdbcOdbcPreparedStatement

    Whenever there is the need to pre-compile a SQL statement, this class may be used. It allows to set the IN parameters on such statements, i.e. such statement may contain placeholders which are filled after pre-compilation but before execution. See set...() for details.

    constructors

    public JdbcOdbcPreparedStatement( Connection dbConnection,
                                      J2ODBC odbcObj,
                                      String sql ) throws SQLException;
    

    Normally called by the JdbcOdbcConnection::prepareStatement() method. dbConnection reflects the current database connection object, odbcObj the current ODBC interface object, and sql the SQL statement to be prepared.

    clearParameter()

    public void clearParameters() throws SQLException;
    

    Resets all parameters.

    execute()

    public boolean execute() throws SQLException;
    

    Executes the prepared statement. If one or more result set(s) is/are available, a true value is returned.

    executeQuery()

    public ResultSet executeQuery() throws SQLException;
    

    Executes the prepared statement and returns a result set.

    executeUpdate()

    public int executeUpdate() throws SQLException;
    

    Executes the prepared statement, that does not return any data, like DELETE, INSERT or UPDATE.

    set...()

    public void setBoolean( int parameterIndex, boolean x ) throws SQLException;
    public void setByte( int parameterIndex, byte x ) throws SQLException;
    public void setBytes( int parameterIndex, byte x[] ) throws SQLException;
    public void setDate( int parameterIndex, java.sql.Date x ) throws SQLException;
    public void setDouble( int parameterIndex, double x ) throws SQLException;
    public void setFloat( int parameterIndex, float x ) throws SQLException;
    public void setInt( int parameterIndex, int x ) throws SQLException;
    public void setLong( int parameterIndex, long x ) throws SQLException;
    public void setBignum( int parameterIndex, Bignum x ) throws SQLException;
    public void setShort( int parameterIndex, short x ) throws SQLException;
    public void setString( int parameterIndex, String x ) throws SQLException;
    public void setTime( int parameterIndex, java.sql.Time x ) throws SQLException;
    public void setTimestamp( int parameterIndex, java.sql.Timestamp x )
            throws SQLException;
    

    Sets a IN parameter with index number parameterIndex (starting with 1) to x. The following table show dependencies between methods and SQL data types:
    method SQL data type(s)
    setBoolean() BIT
    setByte() TINYINT
    setBytes() BINARY, VARBINARY
    setDate() DATE
    setDouble() DOUBLE
    setFloat() FLOAT
    setInt() INTEGER
    setLong() BIGINT
    setBignum() NUMERIC
    setShort() SMALLINT
    setString() CHAR, VARCHAR, LONGVARCHAR
    setTime() TIME
    setTimestamp() TIMESTAMP

    Note:
    Depending on the database software, more than one method (SQL data type) may be used for an IN parameter.

    setNull()

    public void setNull( int parameterIndex, int sqlType ) throws SQLException;
    

    Sets an IN parameter with index number parameterIndex (starting with 1) to NULL. The data type for the IN parameter must be specified by sqlType - see Java.sql.Types for details.

    setObject()

    public void setObject( int parameterIndex, Object x ) throws SQLException;
    public void setObject( int parameterIndex, Object x, int targetSqlType )
            throws SQLException;
    public void setObject( int parameterIndex, Object x, int targetSqlType,
                           int scale ) throws SQLException;
    

    Sets a IN parameter with index number parameterIndex (starting with 1) to x. targetSqlType specifies the target SQL data type (see Java.sql.Types), scale is an optional scaling factor.

    Note:
    If there is no targetSqlType parameter, the appropriate SQL data type is converted by the identified Java data type of x.

    setAsciiStream()

    public void setAsciiStream( int parameterIndex, java.io.InputStream x,
                                int length ) throws SQLException;
    

    On large data (SQL LONGVARCHAR) this method ables to send the parameter data by a stream. parameterIndex (starting with 1) specifies the parameter (by index number), which has to be set. x refers to the stream which sends the data. In length the number of bytes available in the stream is set.

    Note:
    Data is transmitted as ASCII characters.

    setBinaryStream()

    public void setBinaryStream( int parameterIndex, java.io.InputStream x,
                                 int length ) throws SQLException;
    

    On large data (SQL LONGVARBINARY) this method ables to send the parameter data by a stream. parameterIndex (starting with 1) specifies the parameter (by index number), which has to be set. x refers to the stream which sends the data. In length the number of bytes available in the stream is set.

    Note:
    Data is transmitted as binary data.

    setUnicodeStream()

    public void setUnicodeStream( int parameterIndex, java.io.InputStream x,
                                  int length ) throws SQLException;
    

    On large data (SQL LONGVARCHAR) this method ables to send the parameter data by a stream. parameterIndex (starting with 1) specifies the parameter (by index number), which has to be set. x refers to the stream which sends the data. In length the number of bytes available in the stream is set.

    Note:
    Data is transmitted as Unicodes.

    Class JdbcOdbcResultSet

    Every time a SQL statement executed provides results, this class is used to provide an access to that data. There is a cursor, initiated to the begin (some may say: the first row) of the resulting data. The first (next) row of that data is accessed by using the next() method, columns of the row may be gathered using the get...() methods.

    constructors

    public JdbcOdbcResultSet( J2ODBC newDb );
    

    Used by the various execute...() methods in the classes

  • JdbcOdbcCallableStatement,
  • JdbcOdbcPreparedStatement and
  • JdbcOdbcStatement.

    newDb is a reference to the currently ODBC interface used.

    clearWarnings()

    public void clearWarnings() throws SQLException;
    

    Clear warnings in chain list.

    close()

    public void close() throws SQLException;
    

    Closes the cursor associated with the result set. There is then no longer access to the results.

    findColumn()

    public int findColumn( String columnName ) throws SQLException;
    

    Resolves the name columnName and tries to get the appropriate column index (starting with 1) in the result set. An exception is raised if the name could not be resolved.

    get...()

    public boolean getBoolean( String columnName ) throws SQLException;
    public boolean getBoolean( int parameterIndex ) throws SQLException;
    
    public byte getByte( String columnName ) throws SQLException;
    public byte getByte( int parameterIndex ) throws SQLException:
    
    public byte[] getBytes( String columnName ) throws SQLException;
    public byte[] getBytes( int parameterIndex ) throws SQLException;
    
    public java.sql.Date getDate( String columnName ) throws SQLException;
    public java.sql.Date getDate( int parameterIndex ) throws SQLException;
    
    public double getDouble( String columnName ) throws SQLException;
    public double getDouble( int parameterIndex ) throws SQLException;
    
    public float getFloat( String columnName ) throws SQLException;
    public float getFloat( int parameterIndex ) throws SQLException;
    
    public int getInt( String columnName ) throws SQLException;
    public int getInt( int parameterIndex ) throws SQLException;
    
    public long getLong( String columnName ) throws SQLException;
    public long getLong( int parameterIndex ) throws SQLException;
    
    public Bignum getBignum( String columnName, int scale ) throws SQLException;
    public Bignum getBignum( int parameterIndex, int scale ) throws SQLException;
    
    public short getShort( String columnName ) throws SQLException;
    public short getShort( int parameterIndex ) throws SQLException;
    
    public String getString( String columnName ) throws SQLException;
    public String getString( int parameterIndex ) throws SQLException;
    
    public java.sql.Time getTime( String columnName ) throws SQLException;
    public java.sql.Time getTime( int parameterIndex ) throws SQLException;
    
    public java.sql.Timestamp getTimestamp( String columnName )
            throws SQLException;
    public java.sql.Timestamp getTimestamp( int parameterIndex )
            throws SQLException;
    

    Returns the contents of the parameter with index number parameterIndex (starting with 1) or with column name columnName in the appropriate format.

    The following table shows which methods matches SQL data types very closely - on some databases it may be possible to specify a completely other SQL data type for a column/parameter, like CHAR for BIT.
    method SQL data type(s)
    getBoolean() BIT
    getByte() TINYINT
    getBytes() BINARY, VARBINARY
    getDate() DATE
    getDouble() DOUBLE
    getFloat() FLOAT
    getInt() INTEGER
    getLong() BIGINT
    getBignum() NUMERIC
    getShort() SMALLINT
    getString() CHAR, VARCHAR, LONGVARCHAR
    getTime() TIME
    getTimestamp() TIMESTAMP

    getAsciiStream()

    public java.io.InputStream getAsciiStream( int columnIndex )
            throws SQLException;
    public java.io.InputStream getAsciiStream( String columnName )
            throws SQLException;
    

    On large data (SQL LONGVARCHAR) this method ables to receive the result data by a stream. columnIndex (starting with 1) specifies the parameter (by index number), which will be returned. Same does columnName for the other method.

    Note:
    Data is transmitted as ASCII characters.

    getBinaryStream()

    public java.io.InputStream getBinaryStream( int columnIndex )
            throws SQLException;
    public java.io.InputStream getBinaryStream( String columnName )
            throws SQLException;
    

    On large data (SQL LONGVARBINARY) this method ables to receive the result data by a stream. columnIndex (starting with 1) specifies the parameter (by index number), which will be returned. Same does columnName for the other method.

    Note:
    Data is transmitted as binary data.

    getCursorName()

    public String getCursorName() throws SQLException;
    

    Returns the name of the cursor associated with the result set.

    getMetaData()

    public ResultSetMetaData getMetaData() throws SQLException;
    

    Returns an object to a JdbcOdbcResultSetMetaData class. This object can be used to get further informations about a result set.

    getObject()

    public Object getObject( int columnIndex ) throws SQLException;
    public Object getObject( String columnName ) throws SQLException;
    
    public Object getObject( int columnIndex, int targetSqlType )
            throws SQLException;
    public Object getObject( String columnName, int targetSqlType )
            throws SQLException;
    
    public Object getObject( int columnIndex, int targetSqlType, int scale )
            throws SQLException;
    public Object getObject( String columnName, int targetSqlType, int scale )
            throws SQLException;
    

    Returns the contents of the parameter with index number columnIndex (starting with 1) or with column name columnName as object. The type of the object depends on the SQL data type of the column in the result row or on the SQL type value targetSqlType (see Java.sql.Types). The additional parameter scale may specify a scaling factor.

    getUnicodeStream()

    public java.io.InputStream getUnicodeStream( int columnIndex )
            throws SQLException;
    public java.io.InputStream getUnicodeStream( String columnName )
            throws SQLException;
    

    On large data (SQL LONGVARCHAR) this method ables to receive the result data by a stream. columnIndex (starting with 1) specifies the parameter (by index number), which will be returned. Same does columnName for the other method.

    Note:
    Data is transmitted as Unicode characters.

    getWarnings()

    public SQLWarning getWarnings() throws SQLException;
    

    Returns the next warning message stored in the chain, which has been caused by this class.

    next()

    public boolean next() throws SQLException;
    

    In order to get the first/next row of a result set, this method has to be called.

    wasNull()

    public boolean wasNull() throws SQLException;
    

    Returns whether the last access (see get...()) to a column of a result row refered to a NULL value or not.

    Class JdbcOdbcResultSetMetaData

    A object of this class provides informations about types and properties of columns of the result set.

    definitions

    The following definitions are used at the isNullable() method:

  • columnNoNulls - column must not contain NULL values
  • columnNullable - column may contain NULL values
  • columnNullableUnknown - it's not certain whether the column may contain NULL values or not

    constructors

    public JdbcOdbcResultSetMetaData( J2ODBC newDb );
    

    Called by the JdbcOdbcResultSet::getMetaData() method in order to create a new result set meta data object.

    getCatalogName()

    public String getCatalogName( int columnIndex ) throws SQLException;
    

    Returns the name of the catalog containing the table with the specified column (1 <= columnIndex <= getColumnCount()).

    getColumnCount()

    public int getColumnCount() throws SQLException;
    

    Returns the number of columns available in the result set.

    getColumnDisplaySize()

    public int getColumnDisplaySize( int columnIndex ) throws SQLException;
    

    Returns the maximum width in display of the specified column (1 <= columnIndex <= getColumnCount()).

    getColumnLabel()

    public String getColumnLabel( int columnIndex ) throws SQLException;
    

    Returns the suggested column label of the specified column (1 <= columnIndex <= getColumnCount()).

    getColumnName()

    public String getColumnName( int columnIndex ) throws SQLException;
    

    Returns the name of the specified column (1 <= columnIndex <= getColumnCount()).

    getColumnType()

    public int getColumnType( int columnIndex ) throws SQLException;
    

    Returns the JDBC data type of the specified column (1 <= columnIndex <= getColumnCount()). See Java.sql.Types for a description of these types.

    getColumnTypeName()

    public String getColumnTypeName( int columnIndex ) throws SQLException;
    

    Returns the name of the JDBC data type of the specified column (1 <= columnIndex <= getColumnCount()). See Java.sql.Types for a description of these types.

    getPrecision()

    public int getPrecision( int columnIndex ) throws SQLException;
    

    Returns the precision of the specified column (1 <= columnIndex <= getColumnCount()).

    getScale()

    public int getScale( int columnIndex ) throws SQLException;
    

    Returns the scale of the specified column (1 <= columnIndex <= getColumnCount()).

    getSchemaName()

    public String getSchemaName( int columnIndex ) throws SQLException;
    

    Returns the schema name of the table containing the specified column (1 <= columnIndex <= getColumnCount()).

    getTableName()

    public String getTableName( int columnIndex ) throws SQLException;
    

    Returns the name of the table containing the specified column (1 <= columnIndex <= getColumnCount()).

    isAutoIncrement()

    public boolean isAutoIncrement( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) increments automatically on an INSERT or not.

    Note:
    Such columns normally are read-only.

    isCurrency()

    public boolean isCurrency( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) represents a cash value.

    isCaseSensitive()

    public boolean isCaseSensitive( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) is case-sensitive. Normally character based columns are case-sensitive.

    isDefinitelyWritable()

    public boolean isDefinitelyWritable( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) can be modified. This method assures the writability of a column.

    isNullable()

    public int isNullable( int columnIndex ) throws SQLException;
    

    Returns whether if the specified column (1 <= columnIndex <= getColumnCount()) can contain NULL values or not:

  • columnNoNulls - column must not contain NULL values
  • columnNullable - column may contain NULL values
  • columnNullableUnknown - it's not certain whether the column may contain NULL values or not

    isReadOnly()

    public boolean isReadOnly( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) is read-only and may not be modified.

    isSearchAble()

    public boolean isSearchable( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) may be included in a WHERE clause of a SQL statement.

    isSigned()

    public boolean isSigned( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) contains signed values. Normally, only numerical data columns can contain signed values.

    isWritable()

    public boolean isWritable( int columnIndex ) throws SQLException;
    

    Returns true if the specified column (1 <= columnIndex <= getColumnCount()) may be modified.

    Class JdbcOdbcStatement

    The purpose of this class is the representation of a SQL statement in Java. A statement object saves and executes a SQL statement, and then represents a result set (see class ResultSet).

    Note:
    A SQL statement may return only one result set or none, but no more.

    constructors

    public JdbcOdbcStatement( Connection dbConnection, J2ODBC odbcObj )
            throws SQLException;
    

    Called by the JdbcOdbcConnection::createStatement() method in order to create a new statement object.

    cancel()

    public void cancel() throws SQLException;
    

    Cancels the current execution of a SQL statement. This may only take effect, when there is a multi-threading environment.

    clearWarnings()

    public void clearWarnings() throws SQLException;
    

    Clears the last warning occurred from the message queue. See getWarnings(), too.

    close()

    public void close() throws SQLException;
    

    After a executeQuery(), executeUpdate() or execute() call, this method should be used in order to free the object and all associated data.

    execute()

    public boolean execute( String sql ) throws SQLException;
    

    Sends the given SQL statement sql to the database server and returns, whether there is a result set (true) or not (false). The result set may be queried then by the getResultSet() method.

    executeQuery()

    public java.sql.ResultSet executeQuery( String sql ) throws SQLException;
    

    Sends the given SQL statement sql to the database server and returns a result set.

    Note:
    This method may be used on queries.

    executeUpdate()

    public int executeUpdate( String sql ) throws SQLException;
    

    Sends the given SQL statement sql to the database server. The number returned reflects the number of rows being affected.

    Note:
    This method may be used on statements not returning data, like DELETE, INSERT or UPDATE.

    getCursorName()

    public String getCursorName() throws SQLException;
    

    Returns the name of the cursor currently associated with this statement object. The setCursorName() method allows setting of cursor names.

    getMaxFieldSize()

    public int getMaxFieldSize() throws SQLException;
    

    Returns the maximum amount of data, returned for any column value of a SQL data type like

  • BINARY,
  • CHAR,
  • LONGVARBINARY,
  • LONGVARCHAR,
  • VARBINARY,
  • VARCHAR. The limit may be set by the setMaxFieldSize() method.

    getMaxRows()

    public int getMaxRows() throws SQLException;
    

    Returns the maximum numbers of rows, a result set may return. The setMaxRows() method can be used to manipulate this number.

    getMoreResultSet()

    public boolean getMoreResults() throws SQLException;
    

    If there is more than one result set, this method may be used to address the next one. It closes the current result set and prepares the next one for access via getResultSet(). A return code that equals true reflects, that there is another result set, while false is returned when there is no more result set.

    getQueryTimeout()

    public int getQueryTimeout() throws SQLException;
    

    Returns the time (in seconds) the driver will wait on a statement to be executed, before raising a timeout exception. A new timeout value may be set using the setQueryTimeout() method.

    getResultSet()

    public java.sql.ResultSet getResultSet() throws SQLException;
    

    When execute() returns true, this method provides access to the result set.

    getWarnings()

    public SQLWarning getWarnings() throws SQLException;
    

    Returns the last warning occurred. See clearWarnings(), too.

    getUpdateCount()

    public int getUpdateCount() throws SQLException;
    

    The number affected by a DELETE, INSERT or UPDATE command (see execute() or executeUpdate()) can be gathered using this method.

    setCursorName()

    public void setCursorName( String name ) throws SQLException;
    

    Defines the name of the SQL cursor associated with the next execution of a SQL statement. The name will be set to name. The current name of the cursor may be queried by getCursorName().

    setEscapeProcessing()

    public void setEscapeProcessing( boolean enable ) throws SQLException;
    

    If enabled (enable == true) escape sequences in SQL statements will be processed (this is the default). If disabled, there is no extra processing on such sequences.

    setMaxFieldSize()

    public void setMaxFieldSize( int max ) throws SQLException;
    

    Sets the limit (in bytes) to the value of max on columns of the SQL data types

  • BINARY,
  • CHAR,
  • LONGVARBINARY,
  • LONGVARCHAR,
  • VARBINARY,
  • VARCHAR. The limit may be queried by the getMaxFieldSize() method.

    setMaxRows()

    public void setMaxRows( int max ) throws SQLException;
    

    Sets the maximum number of rows returned by a result set to max. The current maximum number of rows is returned by the getMaxRows() method.

    setQueryTimeout()

    public void setQueryTimeout( int seconds ) throws SQLException;
    

    Sets the timeout value on SQL statement processing to seconds seconds. See getQueryTimeout(), too.

    Examples

    This section describe the sample programs coming with this JDBC-ODBC bridge. They are located in the JAVA\demo\ directory.

    Currently, these demos or sample programs are available:

  • Example1 - a simple skeleton program, showing how to connect to the JDBC-ODBC bridge.
  • Example2 - creates a testing table, fills it, shows the data and drops the table.

    Note:
    The following assumptions are made. If one or more are wrong, correct the data in the sources, recompile and the try.

  • There is a database or a data source called test, providing a SQL interface via the JDBC-ODBC bridge.
  • For login on this database or data source, there is a user unknown with an empty password.
  • For example #2, a testing table example2 may be created temporarily.

    Example #1

    //
    // Example #1
    //
    // This example shows the use of the JDBC-ODBC bridge and may be used as a
    // skeleton for further experiments.
    //
    // (c) 1996 by Dirk Ohme, all rights reserved
    //
    
    //---| imports |--------------------------------------------------------------
    import java.net.URL;
    import java.sql.*;
    
    //---| class Example1 |-------------------------------------------------------
    public class Example1 {
            //
            // definitions
            //
            //---| name of the database user |---
            private static final String dbUser = "unknown";
            //---| his password |---
            private static final String dbPwd = "";
            //---| which database source name or database server? |---
            private static final String dbSrc = "test";
    
            //
            // main function
            //
            public static void main( String argv[] ) {
                    try {
                            // enable debugging
                            // DriverManager.setLogStream( System.out );
    
                            // capture JDBC-ODBC bridge
                            String jdbcDriver = "iODBC.sql.JdbcOdbcDriver";
                            Class.forName(jdbcDriver).newInstance();
    
                            // Make sure there is a JDBC-ODBC driver loaded.
                            System.out.println(
                                    "trying to open JDBC interface ..."
                            );
    
                            // make connection to
                            Connection con = DriverManager.getConnection(
                                    "jdbc:odbc:"+dbSrc, dbUser, dbPwd
                            );
                            System.out.println( "connection established" );
    
                            // starting here, SQL statements may be executed
                            // ...
    
                            // close connection
                            con.close();
                            System.out.println( "connection closed" );
    
                    } catch( Exception e ) {
                            System.out.println(e.getMessage());
                            e.printStackTrace();
                    }
            }
    } /* class Example1() */
    
    //===| end of file |===========================================================
    

    Example #2

    //
    // Example #2
    //
    // This example shows the use of the JDBC-ODBC bridge.
    //
    // (c) 1996 by Dirk Ohme, all rights reserved
    //
    
    //---| imports |--------------------------------------------------------------
    import java.net.URL;
    import java.sql.*;
    
    //---| class Example2 |-------------------------------------------------------
    public class Example2 {
            //
            // definitions
            //
            //---| name of the database user |---
            private static final String dbUser = "unknown";
            //---| his password |---
            private static final String dbPwd = "";
            //---| which database source name or database server? |---
            private static final String dbSrc = "test";
            //---| which table to use for testing? |---
            private static final String dbTable = "example2";
    
            //
            // main function
            //
            public static void main( String argv[] ) {
                    try {
                            // enable debugging
                            // DriverManager.setLogStream( System.out );
    
                            // capture JDBC-ODBC bridge
                            String jdbcDriver = "iODBC.sql.JdbcOdbcDriver";
                            Class.forName(jdbcDriver).newInstance();
    
                            // Make sure there is a JDBC-ODBC driver loaded.
                            System.out.println(
                                    "trying to open JDBC interface ..."
                            );
    
                            // make connection to
                            Connection con = DriverManager.getConnection(
                                    "jdbc:odbc:"+dbSrc, dbUser, dbPwd
                            );
                            System.out.println( "connection established" );
    
                            // get a statement object
                            Statement stmt = con.createStatement();
    
                            // fill in some testing data
                            int result = 0;
                            System.out.println( "preparing testing data ..." );
                            result = stmt.executeUpdate(
                                    "create table " + dbTable +
                                    " (namestr CHAR(20), age INT, phone CHAR(40))"
                            );
                            System.out.print( " "+result );
                            result = stmt.executeUpdate(
                                    "insert into " + dbTable +
                                    " values ('Dirk Ohme', 25, '0-7071-123456')"
                            );
                            System.out.print( " "+result );
                            result = stmt.executeUpdate(
                                    "insert into " + dbTable +
                                    " values ('Marius Mustermann', 40, '98765')"
                            );
                            System.out.print( " "+result );
                            result = stmt.executeUpdate(
                                    "insert into " + dbTable +
                                    " values ('Erika Musterfrau', 18, '0815')"
                            );
                            System.out.print( " "+result );
                            System.out.println( " done." );
    
                            // query data
                            ResultSet rs = stmt.executeQuery(
                                    "select * from " + dbTable
                            );
                            System.out.println("getting results:");
                            int row = 0;
                            while( rs.next() ) {
                                    // display results
                                    String user  = rs.getString( 1 );
                                    int    age   = rs.getInt( 2 );
                                    String phone = rs.getString( 3 );
                                    row++;
    
                                    System.out.println(
                                            "  #" + row +
                                            " user = '"  + user  + "'," +
                                            " age = "    + age   + ", " +
                                            " phone = '" + phone + "'"
                                    );
                            }
    
                            // close result set
                            rs.close();
                            System.out.println(
                                    "all rows processed (" + row + ")"
                            );
    
                            // drop testing table
                            System.out.println( "droping testing data ..." );
                            result = stmt.executeUpdate(
                                    "drop table " + dbTable
                            );
                            System.out.println( " "+result+" done." );
    
                            // closing statement handle
                            stmt.close();
                            System.out.println( "statement handle closed" );
    
                            // close connection
                            con.close();
                            System.out.println( "connection closed" );
    
                    } catch( Exception e ) {
                            System.out.println(e.getMessage());
                            e.printStackTrace();
                    }
            }
    } /* class Example2() */
    
    //===| end of file |===========================================================
    

    History

    iODBC has been ported to OS/2 from the Unix Freeware version 2.12. The mSQL 1.0.x and 2.0 CLI / iODBC drivers have been developed by Dirk Ohme.

    Over all, this is the history:

  • V 1.0.6 - 1997/\??
  • iODBC driver for Personal Oracle (tm) 7.x made available for OS/2
  • new autoconf tool for non-Unix operating systems. Under OS/2, autoconf now consists of a Rexx script.
  • V 1.0.5 - 1997/01/24
  • bug-fixes in SQLNumResultCols(), SQLRowCount()
  • SQLSetParam() in iODBC driver manager new implemented
  • bug-fixes in JDBC-ODBC bridge - variable types adapted for multi-platform support (Unix)
  • support for Unix extended, iODBC drivers and manager completed
  • iODBC driver for Oracle (tm) 7.x databases revised
  • V 1.0.4 - 1997/01/09
  • fixed some bugs in the makefiles
  • adaption to Intersolv ODBC driver, so it's compatible with it - NOTE: It may be necessary to re-compile your programs that has been linked against an older version of iODBC!
  • library definition files (*.def) centralized
  • porting back to Unix
  • Oracle 7 database (i)ODBC driver (core level) separated from mSQL driver (Unix only)
  • introducing SYSLEVEL information system (OS/2 only)
  • mSQL ODBC driver updated for latest version of mSQL 2.0 (Beta 1)
  • adaption of JDBC-ODBC bridge to JDBC 1.10 specifications
  • V 1.0.3 - 1996/11/04
  • 'extended setup' feature for iODBC drivers added
  • setup procedure inst_os2 extended - automatic check for update of CONFIG.SYS added
  • configuration tool autoconf.cmd extended with ability to detect a Java Development Kit (JDK)
  • implementation of a Java DataBase Connectivity (JDBC) to ODBC bridge for use with SunSoft's JDBC driver manager under OS/2 (JDBC-ODBC-bridge)
  • bug fix in mSQL 1.x and 2.x ODBC driver - on SQLFreeStmt() with option SQL_CLOSE the statement handle was closed, but this should be only with option SQL_DROP
  • bug fix in mSQL 2.x ODBC driver - the number of resulting rows is stored, the result is gathered by msqlQuery(), the error check at msqlQuery() has been adapted for mSQL 2.x
  • SQLGetData() added to mSQL ODBC drivers
  • adaption to Solid SQL Server 2.1 - works now against their CLI
  • V 1.0.2 - 1996/09/17
  • archived by its own - no more bundling with mSQL
  • archive re-arranged, IPF source file splitted
  • mSQL 2.0 CLI / iODBC driver (core level) implemented
  • iODBC driver manager for OS/2 Presentation Manager designed
  • driver manager DLL renamed from iODBC.DLL to ODBC.DLL
  • comments added to the INI file
  • WPS installation routine added
  • V 1.0.1 - 1996/07/10
  • iODBC driver manager fixed, first working release
  • bundled with mSQL 1.0.16
  • V 1.0.0 - 1996/06/27
  • initial version of the iODBC driver manager
  • mSQL 1.0.x CLI (core level) finished

    Author's Details

    Call-Level Interface (CLI) and (i)ODBC drivers for mSQL 1.0.x and 2.0, (i)ODBC driver manager and JDBC-ODBC bridge were written by:

      Dirk Ohme
      Programmer at transtec AG
      Tübingen, Germany
    
      E-mail:  Dirk.Ohme@transtec.de
      Fidonet: 2:246/2001.9@fidonet
    

    Archive Location

    The primary site for this product is:

      Host:   www.fh-albsig.de (141.87.110.2)
      URL:    http://www.fh-albsig.de/~ohme
      Files:  FILES/iODBC*.zip (Zip 2.0.1 archive)
      Note:   OS/2 port