hello exprts!! i am new 2 database!!! i have oracleXE and jdk 1.6.0_14 installed on windows XP!! i want 2 connect them via my java program.but i am gettting errors after executing the program.

my code is:

import java.sql.*;
//import oracle.jdbc.*;
//import oracle.jdbc.OracleDriver;

  public class OracleConnect
  {
    public static void main(String[] args)throws SQLException
    {
      try
      {
        Class.forName("oracle.jdbc.OracleDriver");
        //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@HOST:1521:XE","hr","hr");
		if(conn != null)
		{ System.out.println("I am Connected to oracle database");
			}
        conn.close();
      } catch (Exception e) {
        System.out.println("ERROR : " + e);
        e.printStackTrace(System.out);
      }
    }
  }

i get the following error:

ERROR : java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at OracleConnect.main(OracleConnect.java:11)

plzz tell me how to solve this problem!!!

Recommended Answers

All 23 Replies

plzz experts reply!!! i am in deep trouble wid dis one!!!

all other community members !!

plzz giv ur views!!!

There is no need for expert. The error spell it out clearly for you

java.lang.[B]ClassNotFound[/B]Exception: oracle.jdbc.OracleDriver
java.lang.[B]ClassNotFound[/B]Exception: oracle.jdbc.OracleDriver

You either do not have connection drivers at all or you did not let application know where to find this driver (either add it through IDE or on compile provide classpath with location of this driver). To download go here

thanxx for replying but i hav alraedy specified the classpath!!
i hav driver named ojdbc14.jar and ojdbc14_g.jar in E:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib and my classpath is::

E:/oraclexe/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc14.jar;E:\oraclexe\app\oracle\product\10.2.0\server\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Teleca Shared;E:\java\bin

now plzz tell me is the classpath correct???
regarding the drivers plzz specify where shud i find them!!!
i hav them already in /lib as told above!!

plzz reply what shud i do now!!

w8in for ur reply!!

plzz sumbody help me in dis!!!!

  1. No need to shout with explanation marks, that will not get you faster respond
  2. This is not necessary E:/oraclexe/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc14.jar
  3. ojdbc14.jar or ojdbc14_g.jar will not help you as documentation clearly state "classes for use with JDK 1.4 and 1.5"
  4. Therefore you either need to use lower JDK or get Oracle 11g and download ojdbc6.jar (Classes for use with JDK 1.6.)

Have nice day.

sorry for exclamation marks. i hav downgraded to jdk1.5.0_19 but still the above code does not run. it shows the same error again!!
is dere ne problem wid da code!! plzz tell me.
w8in for ur reply

Few things you can try

  • If you insisting on using classpath then you should use following declaration E:\Coraclexe\app\oracle\product\10.2.0\server\jdbc\lib
  • On other hand you can direct your IDE where to look for connector, importing JAR for Eclipse here and NetBeans and IntelliJ IDEA here
  • Also check your connection string if @HOST should not be replaced by @localhost, but this is not related to class not found error

plzz somebody help me.i am still stuck at it!!

plzz mods someone help!!

plzz somebody help me.i am still stuck at it!!

plzz mods someone help!!

Would be nice if you notified if you tried above recommendations and what happen instead of crying for help.

well after modifying all the things that u specified in ur previous post,i tried 2 run the program at the command prompt, but the same error repeats again and again. at the run time the code shows the same errors but it compiles successfully. well i hav not tried with netbeans bcoz it is 2 heavy for ma system!!

plzz tell me some method 2 successfully run the program in command prompt only. i shall be thankful 2 u.

Specify your classpath using backslashes and not forward slashes. Also, it would be better if you first tried this thing out by creating a new folder test and placing your class file along with the JAR file in that directory.

c:\Test>java -cp your-oracle-jar-name.jar YourClassName

my classpath was alraedy in back slashes. i tried the test folder and pasted the driver as well as .class file. but when i typed java OracleConnect(name of my file) in command prompt, it still showed the same errors. now tell me what shud i do???
is something wrong wid my code??
plzz solve my problem!!

is dere ne DSN problem?? plzz help me!1

>java OracleConnect(name of my file)

Read my previous reply; just typing the class name won't do; you have to set the classpath.

>java OracleConnect(name of my file)
to run the program i did this!!
rest i did the same as u told above!!
that command showed ACCESS DENIED!!!
so i did it manually by pasting the .class file and the ojdbc14.jar in folder test.

C:\Test>java -cp .;ojdbc14.jar OracleConnect

This is getting interesting.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class TestDB {

  public static void main(String args[]) {
    Connection con = null;

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql://128.0.0.1:3306/dbName",
        "username", "password");

      if(!con.isClosed())
        System.out.println("Successfully connected to " +
          "MySQL server using TCP/IP...");

    } catch(Exception e) {
      //System.err.println("Exception: " + e.getMessage());
      e.printStackTrace();
    } finally {
      try {
        if(con != null)
          con.close();
      } catch(SQLException e) {}
    }
  }
}

While I'm able to run above code, from command line I will receive following stack trace

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at TestDB.main(TestDB.java:22)

PS: Java version 1.6.0_12

>This is getting interesting.

I don't think so. :-)

Post the entire command you are using as it is.

C:\TestDB>javac -cp ojdbc14.jar TestDB.java

C:\TestDB>java -cp .;ojdbc14.jar TestDB
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at TestDB.main(TestDB.java:22)

So, you were expecting a MySQL Driver class in ojdbc14.jar? How about looking for that class in mysql-connector-java.jar file? ;-)

commented: Well spotted +22

Ouch, looks like I messed up big time without spotting my own mistake

import java.sql.*;

public class OracleConnect {
    public static void main(String[] args) throws SQLException {
        try {
            Class.forName("oracle.jdbc.OracleDriver");
            Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "username", "password");
            if (conn != null) {
                System.out.println("I am Connected to oracle database");
            }
            conn.close();
        }
        catch (Exception e) {
            System.out.println("ERROR : " + e);
            e.printStackTrace(System.out);
        }
    }
}

@ sos and Peter_budo ,what should i do now??
plzz somebody help me in this.

plzz post ur answers.

when i typed the two commands on cmd prompt, i got these errors:
it successfully got compiled but did run and gave the following errors!!!!

E:\test>javac -cp ojdbc14.jar OracleConnect.java
E:\test>java -cp .;ojdbc14.jar OracleConnect
ERROR : java.sql.SQLException: Io exception: Got minus one from a read call
java.sql.SQLException: Io exception: Got minus one from a read call
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.jav
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.jav
:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.jav
:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java
414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensi
n.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at jdbc1.main(jdbc1.java:12)

>it successfully got compiled but did run and gave the following
>errors!!!!

This is no longer a problem with your classpath setting which you were initially facing. Since it's an IOException, there might have been a lot of things going wrong here like the database not properly set to listen to connections etc. It would be kinda difficult to come up with a solution for us; do a web search for the given exception "Io exception: Got minus one from a read call" and check out the suggestions given there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.