简体   繁体   中英

Error in Deploying the java(swing, oracle) project on client machin… java.lang.ClassNotFoundException:oracle.jdbc.driver.oracleDriver

I have use oracle 10g database and jdk 1.5 . I'm using eclipse. I have exported the project in .jar file (file is ok).

When I run jar file on client machine then I get

java.lang.ClassNotFoundException:oracl.jdbc.driver.OracleDri.....

I have imported my database on client machine.

My connection code is :

  public void register(){
        try
          {
           // load oracle driver
          Class.forName("oracle.jdbc.driver.OracleDriver");
          // connect using Thin driver
         con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","forbesmarshall","mukeshsir");

         //t1.setText("Connected");
          //con.close();
          }
          catch(Exception ex)
          {
     //         String lo= ex.toString();
              JOptionPane.showMessageDialog(m, ex.toString(),             "Incorrect value", JOptionPane.INFORMATION_MESSAGE);
                ex.printStackTrace();
          }
    }

Hey guys thanks for your reply and helpful suggestion , I got the answer it is related to jar creation and some code problem.. im making it directly jar and its wrong we need to create Runnable jar.. and to load driver we need to use following code..

      try {
      //Class.forName("oracle.jdbc.driver.OracleDriver");
     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
      }catch(Exception ex){
          JOptionPane.showMessageDialog(m, ex.toString(),"Incorrect value", JOptionPane.INFORMATION_MESSAGE);
          ex.printStackTrace();

      }

Have you defined your class path correctly? Which IDE you used to develop the project? I recommend to check 1. jdbc class path 2. Permission issue on directory 3. Sometime there might be a problem of java version.

You should import import oracle.jdbc.*; and set class path pointing to ojdbc6.jar

Looks like oracle driver is not in your classpath you you misspelled driver class name in your code. Error message in your question has incorrect package name: oracl.jdbc.driver.OracleDri..... , but package name in code sample is correct: oracle.jdbc.driver.OracleDriver . Also, you mentioned that you build JAR file from your sources. Make sure that when you run your application, your claspath contains not only this JAR, but also all other JARs your application depends on including Oracle JDBC Driver JAR file.

Modern versions of Oracle JDBC driver do not require you to do Calss.forName at all, by using Service Provider mechanism.

您需要放置oracle jdbc jar“ ojdbc6.jar”,您的问题将得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM