[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

right URL for accessing AS400 with Java

Hi there,
 I have tried this before on the JavaChannel with no answers for the right URL, I'm developing a java programm that access AS400 database, I got the right driver for that (JTOPEN), but I'm not sure if the URL 's got enough parameters(or Wheather they are right or not)
 to acces the AS400 /db2  database

this is my subUrl:

String  subUrl = "//"+Server+"/"+Database + ";Uid="+ strLoginId +";Pwd="+strPassword+";prompt=false;errors=full" ;
      String driver="com.ibm.as400.access.AS400JDBCDriver";
      String protocol="jdbc:as400:";
      String url=protocol+ subUrl ;
2 Solutions
Dave FordSoftware Developer / Database AdministratorCommented:
The following works for me:

String system ... String username ... String password ... String query ... Connection connection = null;

try {
   DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());

  // Get a connection to the database.  Since we do not
  // provide a user id or password, a prompt will appear.
  connection = DriverManager.getConnection("jdbc:as400://" + system, username, password);
  DatabaseMetaData dbMetaData = connection.getMetaData();
catch (SQLException sqle) {
  System.err.println("Error connecting: " + sqle);
catch (Exception ex) {
  System.err.println("Error with input: " + ex);

edwbear1976aAuthor Commented:
Hi , and thank you for your advice

well I just used your  way to connect and at least I got a error that tells me something

try {
            DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
                     conn = DriverManager.getConnection("jdbc:as400://" + system, username, password);
             DatabaseMetaData dbMetaData = conn.getMetaData();

            catch (SQLException e){System.out.println(e.getMessage());e.printStackTrace () ;}
            catch (ClassNotFoundException e){System.out.println(e.getMessage());e.printStackTrace () ;}
     return conn;


And I get this error
C:\jakarta-tomcat-5.0.28\work\Catalina\localhost\sisTextEditor\org\apache\jsp\txtEditorLauncher_jsp.java:56: package com.ibm.as400.access does not exist
            DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
I got the JTOPEN jar files in my classpath
and When I use the NetBeans IDE I added the JTOPEN FILES  to my "libraries" so I got the fullpath completed

but even on NetBeans I got the same error "package doesn't exist"
I know that there must be something really silly that I'm missing like adding at the top anything like an import stament or something... should I use Upercase for that package name?
Dushan De SilvaCommented:
Okay You can try in this way also. You can install DB2 ODBC Driver on your Java server. (When you install crystal reports you will automatically get install DB2 ODBC Driver). Then you can call DB2 as a normal database. And query by SQL (SQLLE). I have successfully used it for DB2 with PHP.

BR Dushan

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now