Using ToolboxME for iSeries to connect to a database on the host server

The JdbcMeConnection class provides a subset of functions available in the IBM® 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];
Note: The previous syntax example is on two lines so you can easily see and print it. Normally, the URL appears on one line with no breaks or extra spaces.

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: Connecting to the server database without specifying a default schema, a port, or JDBC properties

The examples specifies user ID and password 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: Connecting to the server database when specifying the schema and JDBC properties

The example specifies user ID and password 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: Connecting to the server database

The example specifies properties (including user ID and password) by 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: Disconnecting from the database

The example uses the close() method on the connecting object to disconnect from the server:

   c.close();