Results 1 to 7 of 7
  1. #1
    jokobe is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Class

    Hi everyone,

    I am pretty new to Java and and have problem I can't solve.

    Ich have downloaded a file <orathin> from somewhere. At the very beginning it has the code:
    import java.sql.*;
    import java.io.*;

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "user", "pwd");

    and then a query is fired successfully.

    I copied the
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "user", "pwd");

    into a new class file in Eclipse, but now the Class.forName is always throwing an Exception: java.lang.ClassNotFoundException:

    I even copied the whole Class orathin into a new class with a different name, still it is not working.

    Any helpful would be appreciated and thanks in advance

    jokobe

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Cl

    You need the oracle driver for the version of Oracle and Java you are using.

  3. #3
    jokobe is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Cl

    Quote Originally Posted by Tolls View Post
    You need the oracle driver for the version of Oracle and Java you are using.
    The orcale driver is working in the class <orathin> but not in a new class although the code is moved into a new class with copy and paste ...

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Cl

    No.
    You need the jar file that contains the driver itself.
    Depending on the version of things you have it'll be ojdbc<version>.jar.

  5. #5
    jokobe is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Cl

    But why is it workin in class orathin and not in class conn - the same package in the same eclipse environment etc.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Cl

    In one you are referring to the ojdbc.jar in the classpath, and in the other you aren't.
    That's about all I can say.
    That exception is entirely down to the absence of that jar file in the runtime classpath.

  7. #7
    jokobe is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Problems Class.forName("oracle.jdbc.driver.OracleDriver"); working only in one Cl

    thanks...I added the jar to the build path in Eclipse and now it worked, but I am still wondering why it worked in the other class, in the same package and the same project and therefore the same build path.


    Anyhow, thank you very much, guess you saved my day..

    jokobe

Similar Threads

  1. Replies: 10
    Last Post: 03-20-2012, 09:23 AM
  2. Replies: 0
    Last Post: 08-19-2011, 02:19 PM
  3. java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    By kishan.java in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 10-19-2009, 06:34 PM
  4. Replies: 0
    Last Post: 03-21-2008, 02:13 PM
  5. Replies: 1
    Last Post: 03-14-2008, 03:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •