ClassNotFoundException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jorge Cecílio

    #1

    ClassNotFoundException

    Hi all

    I'm having no "luck" trying my first-time connect to an I-SE server from a
    Java application, using JDBC.


    I'm always getting then error:
    "Error: java.lang.Class NotFoundExcepti on: com.informix.jd bc.IfxDriver"

    I suspect the problem is in my CLASSPATH system variable, but I don't know
    how to set it. Or, perhaps, the strings I'm using aren't correct.


    Facts:
    1) My network is "up and running";
    2) Informix-SE is on a Unix remote machine;
    3) My Java app is on Windows XP Home;
    4) Informix Client-SDK 2.81 TC3 is installed on XP;
    5) ODBC has no problems
    (I've an MS-Access app that retrieves data from my SE server. My Java
    app, with JDBC-ODBC bridge, also works fine);
    6) Using Informix Client-SDK dbping, every connection are made successfully,
    except... JDBC!;
    7) In JDBC dbping tab, only "com.informix.j dbc.IfxDriver" seems to be the
    right value since the other two options appears to be for db2
    (COM.ibm.db2.jd bc.app.DB2Drive r and COM.ibm.db2.jdb c.net.DB2Driver )
    8) I'm trying protocol "jdbc:infor mix-sqli". The other option is "jdbc:db2"
    (dbping);
    9) My Java app:
    try {
    //Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ; //jdbc-odbc
    bridge: works fine!
    Class.forName(" com.informix.jd bc.IfxDriver");
    } catch(java.lang .ClassNotFoundE xception e) {
    System.err.prin t("ClassNotFoun dException: ");
    System.err.prin tln(e.getMessag e());
    }

    try {
    //String url = "jdbc:odbc:ifx_ dsn"; //jdbc-odbc bridge: works
    fine!
    String url = "jdbc:infor mix-sqli"
    Connection con = DriverManager.g etConnection(ur l, "login",
    "password") ;
    Statement stmt = con.createState ment();
    //retrieval of values
    (...)
    }
    stmt.close();
    con.close();
    } catch(SQLExcept ion ex) {
    System.err.prin tln("SQLExcepti on: " + ex.getMessage() );
    }



    On JDBC dbping tab is written "This Utility assumes that you have a JDBC
    driver installed and a CLASSPATH set before running DBPING"
    a) What do they mean by having a JDBC driver installed? Isn't this driver
    installed when I installed Informix-SDK? If not, how can I get it?
    b) Do I have to do something like I did to the ODBC driver (by creating and
    configuring a
    DSN)? Where and how?
    c) I know CLASSPATH system variable isn't set. Should I set it in my system?
    By what value? By a path within Informix-SDK folders? Should CLASSPATH be
    set anywhere else (e.g. setnet32)?


    I suspect the problem is in my CLASSPATH system variable, but I don't know
    how to set it. Or, perhaps, the strings I'm using aren't correct.
    Can Anyone help?

    Thanks in advance,
    Jorge Cecilio





  • Tjerk Wolterink

    #2
    Re: ClassNotFoundEx ception

    [cut]

    When you using database you must have the JDBC Driver for that type of database.
    JDBC: Java Database Connectivity.
    JDBC Defines an framework/api for java connecting to sql databases.
    It has some Interface objets in iut that a specific driver for a specific database must implement.

    So you must have a driver for your specific database in your classpath
    The driver you want to use is: com.informix.jd bc.IfxDriver

    [color=blue]
    >
    > On JDBC dbping tab is written "This Utility assumes that you have a JDBC
    > driver installed and a CLASSPATH set before running DBPING"
    > a) What do they mean by having a JDBC driver installed? Isn't this driver
    > installed when I installed Informix-SDK? If not, how can I get it?[/color]

    I think, but am not sure, that the driver is in your Informix-SDK
    But you must include the .jar or .class that is the driver in your classpath.
    [color=blue]
    > b) Do I have to do something like I did to the ODBC driver (by creating and
    > configuring a
    > DSN)? Where and how?[/color]

    dsn? i do not follow you here.
    [color=blue]
    > c) I know CLASSPATH system variable isn't set. Should I set it in my system?
    > By what value? By a path within Informix-SDK folders? Should CLASSPATH be
    > set anywhere else (e.g. setnet32)?[/color]

    When you run your application you must bee sure that the com.informix.jd bc.IfxDriver
    class is in your classpath, see the documentation of Informix where com.informix.jd bc.IfxDriver resides.
    [color=blue]
    >
    > I suspect the problem is in my CLASSPATH system variable, but I don't know
    > how to set it. Or, perhaps, the strings I'm using aren't correct.
    > Can Anyone help?[/color]

    You CAN set your classpath system var to include com.informix.jd bc.IfxDriver but it will then only
    work on your computer. Better is to set the classpath in your application,
    for example if you start your application from a .jar you can include com.informix.jd bc.IfxDriver
    by editing the manifest file of the jar.

    Else you could create a Start script that sets up the classpath first
    [color=blue]
    >
    > Thanks in advance,
    > Jorge Cecilio
    >
    >
    >
    >
    >[/color]

    Comment

    • Stijn Verholen

      #3
      Re: ClassNotFoundEx ception

      Jorge Cecílio wrote:[color=blue]
      > Hi all
      >
      > I'm having no "luck" trying my first-time connect to an I-SE server from a
      > Java application, using JDBC.
      >
      >
      > I'm always getting then error:
      > "Error: java.lang.Class NotFoundExcepti on: com.informix.jd bc.IfxDriver"
      >
      > I suspect the problem is in my CLASSPATH system variable, but I don't know
      > how to set it. Or, perhaps, the strings I'm using aren't correct.
      >
      >
      > Facts:
      > 1) My network is "up and running";
      > 2) Informix-SE is on a Unix remote machine;
      > 3) My Java app is on Windows XP Home;
      > 4) Informix Client-SDK 2.81 TC3 is installed on XP;
      > 5) ODBC has no problems
      > (I've an MS-Access app that retrieves data from my SE server. My Java
      > app, with JDBC-ODBC bridge, also works fine);
      > 6) Using Informix Client-SDK dbping, every connection are made successfully,
      > except... JDBC!;
      > 7) In JDBC dbping tab, only "com.informix.j dbc.IfxDriver" seems to be the
      > right value since the other two options appears to be for db2
      > (COM.ibm.db2.jd bc.app.DB2Drive r and COM.ibm.db2.jdb c.net.DB2Driver )
      > 8) I'm trying protocol "jdbc:infor mix-sqli". The other option is "jdbc:db2"
      > (dbping);
      > 9) My Java app:
      > try {
      > //Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ; //jdbc-odbc
      > bridge: works fine!
      > Class.forName(" com.informix.jd bc.IfxDriver");
      > } catch(java.lang .ClassNotFoundE xception e) {
      > System.err.prin t("ClassNotFoun dException: ");
      > System.err.prin tln(e.getMessag e());
      > }
      >
      > try {
      > //String url = "jdbc:odbc:ifx_ dsn"; //jdbc-odbc bridge: works
      > fine!
      > String url = "jdbc:infor mix-sqli"
      > Connection con = DriverManager.g etConnection(ur l, "login",
      > "password") ;
      > Statement stmt = con.createState ment();
      > //retrieval of values
      > (...)
      > }
      > stmt.close();
      > con.close();
      > } catch(SQLExcept ion ex) {
      > System.err.prin tln("SQLExcepti on: " + ex.getMessage() );
      > }
      >
      >
      >
      > On JDBC dbping tab is written "This Utility assumes that you have a JDBC
      > driver installed and a CLASSPATH set before running DBPING"
      > a) What do they mean by having a JDBC driver installed? Isn't this driver
      > installed when I installed Informix-SDK? If not, how can I get it?
      > b) Do I have to do something like I did to the ODBC driver (by creating and
      > configuring a
      > DSN)? Where and how?
      > c) I know CLASSPATH system variable isn't set. Should I set it in my system?
      > By what value? By a path within Informix-SDK folders? Should CLASSPATH be
      > set anywhere else (e.g. setnet32)?
      >
      >
      > I suspect the problem is in my CLASSPATH system variable, but I don't know
      > how to set it. Or, perhaps, the strings I'm using aren't correct.
      > Can Anyone help?
      >
      > Thanks in advance,
      > Jorge Cecilio
      >
      >
      >
      >
      >[/color]
      Your post is quite long.

      A ClassNotFoundEx ception is simply java telling u it cannot find a class
      that u are trying to load, in this case: com.informix.jd bc.IfxDriver.

      I assume this class is in a jar.
      U can use the system classpath to include the path to this jar, or use
      the -cp option from java.exe to specify where the jar resides.

      For example, if your informix driver is located in a jar called
      informix.jar, residing in the same directory as where u call java.exe to
      start your application, the command would be:
      java -cp informix.jar <your.class>

      hth

      Stijn

      Comment

      Working...