com.ibm.as400.access

Class AS400JDBCDriver

  • All Implemented Interfaces:
    Driver


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

    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: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 Detail

      • AS400JDBCDriver

        public AS400JDBCDriver()

    • Method Detail

      • acceptsURL

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

        public Connection connect(String url,
                         Properties info)
                           throws 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 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:
        SQLException - If the driver is unable to make the connection.
      • connect

        public Connection connect(AS400 system)
                           throws 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:
        SQLException - If the driver is unable to make the connection.
      • connect

        public Connection connect(AS400 system,
                         boolean clone)
                           throws 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 otherwises
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        SQLException - If the driver is unable to make the connection.
      • connect

        public Connection connect(AS400 system,
                         Properties info,
                         String schema,
                         boolean clone)
                           throws 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 otherwises
        Returns:
        The connection to the database or null if the driver does not understand how to connect to the database.
        Throws:
        SQLException - If the driver is unable to make the connection.
      • connect

        public Connection connect(AS400 system,
                         Properties info,
                         String schema)
                           throws 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:
        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 Driver
        Returns:
        The major version number.
      • getMinorVersion

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

        public DriverPropertyInfo[] getPropertyInfo(String url,
                                           Properties info)
                                             throws SQLException
        Returns an array of DriverPropertyInfo objects that describe the properties that are supported by this driver.
        Specified by:
        getPropertyInfo in interface 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:
        SQLException - If an error occurs.
      • jdbcCompliant

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

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