com.ibm.jtopenlite.database.jdbc
Class JDBCDriver

java.lang.Object
  extended by com.ibm.jtopenlite.database.jdbc.JDBCDriver
All Implemented Interfaces:
Driver

public class JDBCDriver
extends Object
implements Driver

A JDBC 3.0 driver that accesses DB2 for IBM i databases.

The jtopenlite driver is designed to provide a JDBC driver suitable for use on mobile devices. Because of this, the following features are not supported.

To use this driver, the application or caller must register the driver with the JDBC DriverManager. This class also registers itself automatically when it is loaded.

After registering the driver, applications make connection requests to the DriverManager, which dispatches them to the appropriate driver. This driver accepts connection requests for databases specified by the URLs that match the following syntax:

jdbc:jtopenlite://system-name

The driver uses the specified system name to connect to a corresponding IBM i system.

The following example URL specifies a connection to the database on system mysystem.helloworld.com.

jdbc:jtopenlit://mysystem.helloworld.com

The following is a simple JDBC program

import java.sql.*;
import java.io.*;
public class RunSql {
   public final static String PROMPT="ENTER SQL STATEMENT or exit > ";
   public static void main(String[] args) {
           try {
                   Class.forName("com.ibm.jtopenlite.database.jdbc.JDBCDriver");
                   String url = args[0];
                   String userid = args[1];
                   String password = args[2];
                   Connection connection = DriverManager.getConnection(url, userid, password);
                   Statement statement = connection.createStatement();
                   BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                   System.out.print(PROMPT);
                   String line = reader.readLine().trim();
                   while (! line.equalsIgnoreCase("exit") ) {
                           try {
                                   boolean results = statement.execute(line);
                                   if (results) {
                                           ResultSet rs = statement.getResultSet();
                                           ResultSetMetaData rsmd = rs.getMetaData();
                                           int columnCount = rsmd.getColumnCount();
                                           StringBuffer sb = new StringBuffer();
                                           while (rs.next()) {
                                                  sb.setLength(0);
                                                  sb.append(rs.getString(1));
                                                  for (int column = 2; column <= columnCount; column++) {
                                                          sb.append(",");
                                                          sb.append(rs.getString(column));
                                                  }
                                                  System.out.println(sb.toString());
                                           }
                                   }
                           } catch (SQLException sqlex) {
                                   System.out.println("SQLException caught");
                                   System.out.println(sqlex.toString());
                           }
                           System.out.print(PROMPT);
                           line = reader.readLine().trim();
                   }

           } catch (Exception e) {
                   System.out.println("Fatal error occurred");
             e.printStackTrace(System.out);
             System.out.println("Usage: java com.ibm.jtopenlite.samples.RunSql JDBCURL USERID PASSWORD");

           }
   }

}


Field Summary
static String DATABASE_PRODUCT_NAME_
           
static String DRIVER_LEVEL_
           
static String DRIVER_NAME_
           
static int JDBC_MAJOR_VERSION_
           
static int JDBC_MINOR_VERSION_
           
static int MAJOR_VERSION_
           
static int MINOR_VERSION_
           
static String URL_PREFIX_
           
 
Constructor Summary
JDBCDriver()
           
 
Method Summary
 boolean acceptsURL(String url)
           
 Connection connect(String url, Properties info)
           
 int getMajorVersion()
           
 int getMinorVersion()
           
 DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
           
 boolean jdbcCompliant()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATABASE_PRODUCT_NAME_

public static final String DATABASE_PRODUCT_NAME_
See Also:
Constant Field Values

DRIVER_NAME_

public static final String DRIVER_NAME_
See Also:
Constant Field Values

DRIVER_LEVEL_

public static final String DRIVER_LEVEL_
See Also:
Constant Field Values

MAJOR_VERSION_

public static final int MAJOR_VERSION_
See Also:
Constant Field Values

MINOR_VERSION_

public static final int MINOR_VERSION_
See Also:
Constant Field Values

JDBC_MAJOR_VERSION_

public static final int JDBC_MAJOR_VERSION_
See Also:
Constant Field Values

JDBC_MINOR_VERSION_

public static final int JDBC_MINOR_VERSION_
See Also:
Constant Field Values

URL_PREFIX_

public static final String URL_PREFIX_
See Also:
Constant Field Values
Constructor Detail

JDBCDriver

public JDBCDriver()
Method Detail

acceptsURL

public boolean acceptsURL(String url)
                   throws SQLException
Specified by:
acceptsURL in interface Driver
Throws:
SQLException

connect

public Connection connect(String url,
                          Properties info)
                   throws SQLException
Specified by:
connect in interface Driver
Throws:
SQLException

getMajorVersion

public int getMajorVersion()
Specified by:
getMajorVersion in interface Driver

getMinorVersion

public int getMinorVersion()
Specified by:
getMinorVersion in interface Driver

getPropertyInfo

public DriverPropertyInfo[] getPropertyInfo(String url,
                                            Properties info)
Specified by:
getPropertyInfo in interface Driver

jdbcCompliant

public boolean jdbcCompliant()
Specified by:
jdbcCompliant in interface Driver

toString

public String toString()
Overrides:
toString in class Object