Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    4

    Red face Unanswered: Cannot net connect to DB2 via JBuilder9

    here is my code

    Code:
    import java.sql.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.StringTokenizer;
    
    
    public class daqian {
    
            static
              {   try
                      {   Class.forName ("COM.ibm.db2.jdbc.app.DB2Driver").newInstance ();
                      }
                      catch (Exception e)
                      {   System.out.println ("\n  Error loading DB2 Driver...\n");
                              System.out.println (e);
                              System.exit(1);
                      }
              }
    
            public static void main(String[] args) {
                    Connection con = null;
    
                      //  URL is jdbc:db2:dbname
                      String url = "jdbc:db2://192.168.0.101:7000/project";
    
                      try {
                             if (args.length == 0) {
                                    //  connect with default id/password
                                    con = DriverManager.getConnection(url);
                                    }
                             else if (args.length == 2) {
                                    String userid = args[0];
                                    String passwd = args[1];
    
                                    //  connect with user-provided username and password
                                    con = DriverManager.getConnection(url, userid, passwd);
                                    }
                             else {
                                    System.out.println("\nUsage: java DB2Appl [username password]\n");
                                    System.exit(0);
                             }
    
                             //  retrieve data from the database
                             String input = JOptionPane.showInputDialog("Restaurant Name:");
                             Statement stmt = con.createStatement();
    
                             ResultSet rs = stmt.executeQuery("SELECT * from rs.restaurant where name=" + "'" + input + "'");
    
                             System.out.println("Received results:");
    
                             //  display the result set
                             //  rs.next() returns false when there are no more rows
                             while (rs.next()) {
                                    String str1 = rs.getString(1);
                                    String str2 = rs.getString(2);
                                    String str3 = rs.getString(3);
                                    String str4 = rs.getString(4);
                                    String str5 = rs.getString(5);
                                    String str6 = rs.getString(6);
    
                                    System.out.println(str1 + " " + str2 + " " + str3 + " " + str4
                                                        + " " + str5 + " " + str6);
                                    System.out.print("\n");
                             }
    
                             rs.close();
                             stmt.close();
    
    
                      } catch( Exception e ) {
                             e.printStackTrace();
                      }
               }
    }

    I set up all the libiraies required in Jbuilder9, and I am keeping get this error message:

    C:\JBuilder9\jdk1.4\bin\javaw -classpath "C:\Documents and Settings\Owner\jbproject\database\classes;C:\JBuil der9\lib\jbcl.jar;C:\JBuilder9\lib\dx.jar;C:\JBuil der9\lib\beandt.jar;C:\ibmdb2_java\java\db2java.zi p;C:\JBuilder9\jdk1.4\jre\lib\rt.jar;C:\JBuilder9\ jdk1.4\jre\lib\i18n.jar;C:\JBuilder9\jdk1.4\jre\li b\sunrsasign.jar;C:\JBuilder9\jdk1.4\jre\lib\jsse. jar;C:\JBuilder9\jdk1.4\jre\lib\jce.jar;C:\JBuilde r9\jdk1.4\jre\lib\charsets.jar;C:\JBuilder9\jdk1.4 \jre\classes;C:\JBuilder9\jdk1.4\lib\tools.jar" database.daqian

    Error loading DB2 Driver...


    java.sql.SQLException: java.lang.UnsatisfiedLinkError: no db2jdbc in java.library.path


    as you can see, i already had "C:\ibmdb2_java\java\db2java.zip" in the path..

    so what should I do? thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    12
    To start, use jdk1.3 instead of 1.4. It may sound weard, but believe me, lot of errors with db2 and java, did I solve by just using 1.3 instead of 1.4.

    Instead of writing
    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance ();

    try
    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

    Try also to put the statement into the main routine, instead of putting it into a static body. This isn't maybe the cleanest way, but once your code works, you can still make it 'clean'.

  3. #3
    Join Date
    Nov 2003
    Posts
    4
    hello

    the same code on my laptop works, the only difference is that my laptop has IBM DB2 UD installed...

    dont know why..

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    12
    I'm far from an expert, so what I tell can be wrong.
    But I think if you have DB2 locally installed, you can use
    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver")

    But when you want to connect to a remote database, you should use
    Class.forName("COM.ibm.db2.jdbc.net.DB2Driver")

    Unless you connect to DB2 8.1, then you can use
    Class.forName("com.ibm.db2.jcc.DB2Driver")
    for both local and distance DB.

    I always use the last named driver.

Posting Permissions

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