Connecting Java to Oracle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • owen
    New Member
    • Feb 2007
    • 2

    #1

    Connecting Java to Oracle

    Hi,

    I've been trying for ages to connect to my Oracle 9.2.0 database from Java.

    I am attempting to create a thin connection.

    The necessary drivers were installed with the database and I have all the relevant files under the folder C:\oracle\ora92 \jdbc\lib

    Initially I had JDK 6 downloaded from Sun's website, but I didn't think it would be compatible with the older database, so I then replaced that with SDK 1.4.

    I created the environment variable CLASSPATH and having searched for help all over the Internet I have tried each of the following values:

    C:\oracle\ora92 \jdbc\lib\
    C:\oracle\ora92 \jdbc\lib\class es12.zip
    C:\oracle\ora92 \jdbc\lib\class es111.zip
    C:\oracle\ora92 \jdbc\lib\ojdbc 14.jar

    When I attempt to run the following....

    Class.forName(" oracle.jdbc.dri ver.OracleDrive r");

    or...

    DriverManager.r egisterDriver(n ew oracle.jdbc.dri ver.OracleDrive r());

    ... I get a ClassNotFoundEx ception.

    I have "import java.sql.*;" at the top of my class.

    One website I found said that I should also import oracle.jdbc.*; but that wont compile for the same, not found, reason.

    Can anyone help me? It is probably something really obvious and silly that I am not doing, but isn't it always?!

    Thanks,
    Owen
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by owen
    Hi,

    I've been trying for ages to connect to my Oracle 9.2.0 database from Java.

    I am attempting to create a thin connection.

    The necessary drivers were installed with the database and I have all the relevant files under the folder C:\oracle\ora92 \jdbc\lib

    Initially I had JDK 6 downloaded from Sun's website, but I didn't think it would be compatible with the older database, so I then replaced that with SDK 1.4.

    I created the environment variable CLASSPATH and having searched for help all over the Internet I have tried each of the following values:

    C:\oracle\ora92 \jdbc\lib\
    C:\oracle\ora92 \jdbc\lib\class es12.zip
    C:\oracle\ora92 \jdbc\lib\class es111.zip
    C:\oracle\ora92 \jdbc\lib\ojdbc 14.jar

    When I attempt to run the following....

    Class.forName(" oracle.jdbc.dri ver.OracleDrive r");

    or...

    DriverManager.r egisterDriver(n ew oracle.jdbc.dri ver.OracleDrive r());

    ... I get a ClassNotFoundEx ception.

    I have "import java.sql.*;" at the top of my class.

    One website I found said that I should also import oracle.jdbc.*; but that wont compile for the same, not found, reason.

    Can anyone help me? It is probably something really obvious and silly that I am not doing, but isn't it always?!

    Thanks,
    Owen
    You can always attach the file directly to the project. This might be different per IDE, but I believe if you right-click on whatever is your 'libraries' folder is in the project, you will be able to choose something along the lines of "add jar/folder" and if you attach the oracle jdbc driver there, then you can register it without having it in the classpath.

    If you think your classpath is correct, though, this example of an oracle connection might help?

    Comment

    • hirak1984
      Contributor
      • Jan 2007
      • 316

      #3
      find ojdbc14.jar and add it to the library as an external jar.

      hopefully your problem will get solved

      Comment

      • owen
        New Member
        • Feb 2007
        • 2

        #4
        Thanks for the help.

        I actually solved the problem by setting my classpath through a cmd prompt rather than through the environment variables. Not sure why there should be a difference, but there was!

        Comment

        Working...