Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2002
    Posts
    8

    Question Unanswered: DB2 and Java question

    Hi. I'm running a small custom Java utility on an AIX server connecting to a DB2 database. DB2 allows for implicit connections, which means that through the UNIX command line I can connect to the DB without providing a password. It knows that since I'm authenicated on the server, I must also be authenicated on the DB (assuming I have an account created at the DB level).

    Is there a way to do this in Java? I want to connect to the same DB2 database in my Java utility without having to provide a password. Can this be done?

    NOTE: I am calling the Java app/class from a KSH script.

    Thanks!
    - Dylan

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    I'm not sure if this is gonna work but you could try using the "app" (type 2) driver (COM.ibm.db2.jdbc.app.DB2Driver). You'll need to catalog your database locally and specify the jdbc url as "jdbc:db2:YOURDB".

  3. #3
    Join Date
    Aug 2002
    Posts
    8
    Hi. I'm getting an odd Java error. My class just tries to establish a connection to a DB2 database - that's it. Here's the error:

    java.lang.NoClassDefFoundError: java/security/PrivilegedAction
    at COM.ibm.db2.jdbc.app.DB2Driver.<init>(Compiled Code)
    at
    at TestConnect.main(Compiled Code)

    The db2java.zip file is in the classpath. I've never seen this error before, and I'm unclear as to what the problem is.

    Here's my code:

    Connection db;
    String dbURL = "jdbc:db2:icmdb01";
    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
    System.out.println("Connecting to Database URL = " + dbURL);
    db = DriverManager.getConnection(dbURL);
    System.out.println("Connected to " + dbURL + "\nNow closing DB...");
    db.close();

    Again, I'm running this on an AIX server. I've added all the necessary Java/DB2 packages to the classpath (I think).

    Any ideas?

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Looks like your JRE version doesn't match DB2 requirements. You'll probably need to install JRE that supports the version of DB2 you're using.

  5. #5
    Join Date
    Aug 2002
    Posts
    8
    Thanks. The problem was that I also needed to have the rt.jar file in my classpath. Once I added this it worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •