com.ibm.as400.access

Class AS400JDBCDriver

  • java.lang.Object
    • com.ibm.as400.access.AS400JDBCDriver
  • All Implemented Interfaces:
    java.sql.Driver


    public class AS400JDBCDriver
    extends java.lang.Object
    implements java.sql.Driver
    A JDBC 3.0/4.0/4.2/4.3 driver that accesses DB2 for IBM i databases.

    To use this driver, the application or caller must register the driver with the JDBC DriverManager prior to JDBC 4.0. This class also registers itself automatically when it is loaded. When using the JDBC 4.0 or later versions, the driver is automatically registered.

    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:as400://system-name/default-schema;properties
    

    The driver uses the specified system name to connect to a corresponding IBM i system. If an IPV6 address is used as the system name, it must be enclosed within braces, i.e. [fd13:ac12:18:17::16]. If a system name is not specified, then the user will be prompted.

    The default SQL schema is optional and the driver uses it to resolve unqualified names in SQL statements. If no default SQL schema is set, then the driver resolves unqualified names based on the naming convention for the connection. If SQL naming is being used, and no default SQL schema is set, then the driver resolves unqualified names using the schema with the same name as the user. If system naming is being used, and no default SQL schema is set, then the driver resolves unqualified names using the server job's library list. See JDBC properties for more details on how to set the naming convention and library list.

    Several properties can optionally be set within the URL. They are separated by semicolons and are in the form:

    name1=value1;name2=value2;...
    
    See JDBC properties for a complete list of properties supported by this driver.

    The following example URL specifies a connection to the database on system mysystem.helloworld.com with mylibrary as the default SQL schema. The connection will use the system naming convention and return full error messages:

    jdbc:as400://mysystem.helloworld.com/mylibrary;naming=system;errors=full
    
    • Constructor Summary

      Constructors 
      Constructor and Description
      AS400JDBCDriver() 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      boolean acceptsURL(java.lang.String url)
      Indicates if the driver understands how to connect to the database named by the URL.
      java.sql.Connection connect(AS400 system)
      Connects to the database on the specified system.
      java.sql.Connection connect(AS400 system, boolean clone)
      Connects to the database on the specified system.
      java.sql.Connection connect(AS400 system, java.util.Properties info, java.lang.String schema)
      Connects to the database on the specified system.
      java.sql.Connection connect(AS400 system, java.util.Properties info, java.lang.String schema, boolean clone)
      Connects to the database on the specified system.
      java.sql.Connection connect(java.lang.String url, java.util.Properties info)
      Connects to the database named by the specified URL.
      java.sql.Connection connect(java.lang.String url, java.util.Properties info, char[] password)
      Connects to the database named by the specified URL.
      java.sql.Connection connect(java.lang.String url, java.lang.String userid, char[] password)
      Connects to the database named by the specified URL using the specified userid and password.
      int getMajorVersion()
      Returns the driver's major version number.
      int getMinorVersion()
      Returns the driver's minor version number.
      java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String url, java.util.Properties info)
      Returns an array of DriverPropertyInfo objects that describe the properties that are supported by this driver.
      boolean jdbcCompliant()
      Indicates if the driver is a genuine JDBC compliant driver.
      java.lang.String toString()
      Returns the name of the driver.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AS400JDBCDriver

        public AS400JDBCDriver()
    • Method Detail

      • acceptsURL

        public boolean acceptsURL(java.lang.String url)
                           throws java.sql.SQLException
        Indicates if the driver understands how to connect to the database named by the URL.
        Specified by:
        acceptsURL in interface java.sql.Driver
        Parameters:
        url - The URL for the database.
        Returns:
        true if the driver understands how to connect to the database; false otherwise.
        Throws:
        java.sql.SQLException - If an error occurs.
      • connect

        public java.sql.Connection connect(java.lang.String url,
                                  java.lang.String userid,
                                  char[] password)
                                    throws java.sql.SQLException
        Connects to the database named by the specified URL using the specified userid and password.
        Parameters:
        url - The URL for the database.
        userid - The userid for the connection
        password - The password for the connection. The caller should clear the password from the array after the method returns.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • connect

        public java.sql.Connection connect(java.lang.String url,
                                  java.util.Properties info)
                                    throws java.sql.SQLException
        Connects to the database named by the specified URL. There are many optional properties that can be specified. Properties can be specified either as part of the URL or in a java.util.Properties object. See JDBC properties for a complete list of properties supported by this driver.
        Specified by:
        connect in interface java.sql.Driver
        Parameters:
        url - The URL for the database.
        info - The connection properties.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • connect

        public java.sql.Connection connect(java.lang.String url,
                                  java.util.Properties info,
                                  char[] password)
                                    throws java.sql.SQLException
        Connects to the database named by the specified URL. There are many optional properties that can be specified. Properties can be specified either as part of the URL or in a java.util.Properties object. See JDBC properties for a complete list of properties supported by this driver.
        Parameters:
        url - The URL for the database.
        info - The connection properties.
        password - The password as a char array. The caller should clear the char array after returning.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • connect

        public java.sql.Connection connect(AS400 system)
                                    throws java.sql.SQLException
        Connects to the database on the specified system.

        Note: Since this method is not defined in the JDBC Driver interface, you typically need to create a Driver object in order to call this method:

                AS400JDBCDriver d = new AS400JDBCDriver();
                AS400 o = new AS400(myAS400, myUserId, myPwd);
                Connection c = d.connect (o);
                
        Parameters:
        system - The IBM i system to connect.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • connect

        public java.sql.Connection connect(AS400 system,
                                  boolean clone)
                                    throws java.sql.SQLException
        Connects to the database on the specified system.

        Note: Since this method is not defined in the JDBC Driver interface, you typically need to create a Driver object in order to call this method:

                AS400JDBCDriver d = new AS400JDBCDriver();
                AS400 o = new AS400(myAS400, myUserId, myPwd);
                Connection c = d.connect (o, false);
                
        Parameters:
        system - The IBM i system to connect.
        clone - True if the AS400 object should be cloned, false otherwise.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • connect

        public java.sql.Connection connect(AS400 system,
                                  java.util.Properties info,
                                  java.lang.String schema,
                                  boolean clone)
                                    throws java.sql.SQLException
        Connects to the database on the specified system.

        Note: Since this method is not defined in the JDBC Driver interface, you typically need to create a Driver object in order to call this method:

                AS400JDBCDriver d = new AS400JDBCDriver();
                AS400 o = new AS400(myAS400, myUserId, myPwd);
                String mySchema = "defaultSchema";
                Properties prop = new Properties();
                Connection c = d.connect (o, prop, mySchema, false);
                
        Parameters:
        system - The IBM i system to connect.
        info - The connection properties.
        schema - The default SQL schema or null meaning no default SQL schema specified.
        clone - True if the AS400 object should be cloned, false otherwise.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • connect

        public java.sql.Connection connect(AS400 system,
                                  java.util.Properties info,
                                  java.lang.String schema)
                                    throws java.sql.SQLException
        Connects to the database on the specified system. There are many optional properties that can be specified. Properties can be specified in a java.util.Properties object. See JDBC properties for a complete list of properties supported by this driver.

        Note: Since this method is not defined in the JDBC Driver interface, you typically need to create a Driver object in order to call this method:

                AS400JDBCDriver d = new AS400JDBCDriver();
                String mySchema = "defaultSchema";
                Properties p = new Properties();
                AS400 o = new AS400(myAS400, myUserId, myPwd);
                Connection c = d.connect (o, p, mySchema);
                
        Parameters:
        system - The IBM i system to connect.
        info - The connection properties.
        schema - The default SQL schema or null meaning no default SQL schema specified.
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If the driver is unable to make the connection.
      • getMajorVersion

        public int getMajorVersion()
        Returns the driver's major version number.
        Specified by:
        getMajorVersion in interface java.sql.Driver
        Returns:
        The major version number.
      • getMinorVersion

        public int getMinorVersion()
        Returns the driver's minor version number.
        Specified by:
        getMinorVersion in interface java.sql.Driver
        Returns:
        The minor version number.
      • getPropertyInfo

        public java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String url,
                                                    java.util.Properties info)
                                                      throws java.sql.SQLException
        Returns an array of DriverPropertyInfo objects that describe the properties that are supported by this driver.
        Specified by:
        getPropertyInfo in interface java.sql.Driver
        Parameters:
        url - The URL for the database.
        info - The connection properties.
        Returns:
        The descriptions of all possible properties or null if the driver does not understand how to connect to the database.
        Throws:
        java.sql.SQLException - If an error occurs.
      • jdbcCompliant

        public boolean jdbcCompliant()
        Indicates if the driver is a genuine JDBC compliant driver.
        Specified by:
        jdbcCompliant in interface java.sql.Driver
        Returns:
        Always true.
      • toString

        public java.lang.String toString()
        Returns the name of the driver.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The driver name.