简体   繁体   中英

jdbc to oracle 11g xe. class not found error

I've installed oracle 10g express edition. I need to connect it to java program, used jdbc. I have ojdbc6_g.jar and set its class path. I am getting class not found error.Code is given below. Please help

import java.sql.*;

public class OraThin {

    public static void main(String[] args) {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//Terminator:1521/CLRExtProc", "scott", "tiger"); //hostname=Terminator, sid=CLRxtProc
            Statement s = con.createStatement();
            s.execute("insert into student values('PQR',10)");
            s.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

The stack trace:

java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver at 
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at 
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at 
java.security.AccessController.doPrivileged(Native Method) at 
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at 
java.lang.ClassLoader.loadClass(ClassLoader.java:423) at 
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at 
java.lang.ClassLoader.loadClass(ClassLoader.java:356) at 
java.lang.ClassLoader.forName0(Native Method) at OraThin.main(OraThin.java:6) 

Try these steps to debug your problem:

  • Make sure the ojdbc6_g.jar file is not corrupted. Open it in an archive app like Winzip or 7-Zip and check that it opens without errors

  • Copy the ojdbc6_g.jar into the same folder as OraThin.class file and execute the following exactly as below:

    java -cp ojdbc6_g.jar; OraThin

Hopefully you will resolve your problem soon

转到您的项目,属性>库>添加jar>添加ojdb7.jar

The jar is not in the class path. You could try

java -classpath 'path to ojdbc6_g.jar;.' OraThin

ojdbc6_g.jar is debug version, hence its name is bit different. May be your scripts are looking for ojdbc6.jar or ojdbc6.jar (If you are using an IDE, you will able to create a library and add to the project module).

This will definitely work, your code is absolutely correct. Please set the classpath correctly or alternatively you may also use ojdbc6.jar file to solve your problem.C:

Try this : 1: open command prompt 2: go to the path where your java files present 3: type set classpath=.;C:\\oraclexe.....\\ojdbc14.jar;%classpath% 4: compile your code with javac -d . filename.java

Tell me what it shows.

You can find the jar at the following location [oracle install folder]\\app\\oracle\\product\\10.2.0\\server\\jdbc\\lib

look for ojdbc14.jar and use it in the classpath as suggested above.

Example: D:\\oraclexe\\app\\oracle\\product\\10.2.0\\server\\jdbc\\lib\\ojdbc14.jar

after searching for about 10 days finally got answer to my own question. No error or exception. connection successfully established. just needed to do following things 1. set path c:\\jdk1.7.0\\bin;c:\\oraclexe\\app\\oracle\\product\\10.2.0\\server\\BIN 2. set classpath=.;c:\\oraclexe\\app\\oracle\\product\\10.2.0\\server\\jdbc\\lib\\ojdbc14.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