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

x
  • 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 ;
        
0
edwbear1976a
Asked:
edwbear1976a
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();
  connection.close();
}
catch (SQLException sqle) {
  System.err.println("Error connecting: " + sqle);
}
catch (Exception ex) {
  System.err.println("Error with input: " + ex);
}

HTH,
DaveSlash
0
 
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();
             conn.close();

           
            }
            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
%classpath%;C:\WINNT\java\Packages;C:\windows\system32;C:\jakarta-tomcat-5.0.28\common\lib\servlet-api;C:\jakarta-tomcat-5.0.28\common\lib\jsp-api;c:\sybase\ASEP\3pclass.zip;c:\sybase\ASEP\monclass.zip;C:\IBMJTOPEN\lib\jt400.jar;C:\IBMJTOPEN\lib\util400.jar;C:\IBMJTOPEN\lib\jt400Servlet.jar;
 
and When I use the NetBeans IDE I added the JTOPEN FILES  to my "libraries" so I got the fullpath completed
jt400.jar:
com
      ibm
            as400
                     access
                                as400JDBCDRIVER.class

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?
0
 
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
0

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