Begin changeUsing ToolboxME for iSeries to connect to a database on the host server

The JdbcMeConnection class provides a subset of functions available in the Toolbox for Java AS400JDBCConnection class. Use JdbcMeConnection to enable your Tier0 device to access DB2 Universal Database (UDB) databases on the host server.

Note: To use ToolboxMe for iSeries classes, you must separately download and set up the ToolboxME for iSeries component. For more information, see ToolboxME for iSeries requirements and installation.

Use JdbcMeDriver.getConnection() to connect to the server database. The getConnection() method takes a uniform resource locator (URL) string as an argument, the user ID, and password. The JDBC driver manager on the host server attempts to locate a driver that can connect to the database that is represented by the URL. JdbcMeDriver uses the following syntax for the URL:

      jdbc:as400://server-name/default-schema;meserver=<server>[:port];[other properties];

You must specify a server name, or JdbcMeDriver throws an exception. The default schema is optional. If you do not specify a port, the JdbcMeDriver uses port 3470. Also, you can set a variety of JDBC properties within the URL. To set properties, use the following syntax:

      name1=value1;name2=value2;...

See JDBC properties for a complete list of properties supported by JdbcMeDriver.

Examples: Using the JdbcMeDriver to connect to a server

Example 1: Connecting to the server database without specifying a default schema, a port, or JDBC properties. User ID and password are specified as parameters on the method.

         // Connect to system 'mysystem'. No default schema, port or
         // properties are specified.
    Connection c  = JdbcMeDriver.getConnection
         ("jdbc:as400://mysystem.helloworld.com;
           meserver=myMeServer;"
          "auser",
          "apassword");

Example 2: Connecting to the server database when specifying the schema and JDBC properties. User ID and password are specified as parameters on the method.

         // Connect to system 'mysystem'. Specify a schema and
         // two JDBC properties. Do not specify a port.
    Connection c2 = JdbcMeDriver.getConnection
         ("jdbc:as400://mysystem.helloworld.com/mySchema;
          meserver=myMeServer;
          naming=system;
          errors=full;"
          "auser",
          "apassword");

Example 3: Connecting to the server database; properties (including user ID and password) are specified using a uniform resource locator (URL).

         // Connect using properties. The properties are set on the URL
         // instead of through a properties object.
     Connection c = DriverManager.getConnection
          ("jdbc:as400://mySystem;
            meserver=myMeServer;
            naming=sql;
            errors=full;
            user=auser;
            password=apassword");
 

Example 4: Disconnecting from the database. Use the close() method on the connecting object to disconnect from the server:

     c.close();
End change