9 Replies Latest reply: Jul 12, 2011 2:04 PM by Joe Weinstein-Oracle RSS

    error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver

    874393

      m just trying a basic example of database connectivity nd m getting error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver

      m using jdk 1.6
      orcle 10g
      netbeans 5.5

      my code is



      import java.io.*;
      import java.net.*;

      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.sql.*;

      public class connect extends HttpServlet {



      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try
      {
      Class.forName("Oracle.jdbc.driver.OracleDriver");
      Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","ankita");
      Statement stmt=con.createStatement();
      String s="select * from memp";
      ResultSet rs=stmt.executeQuery(s);
      while(rs.next())
      {
      out.println(rs.getInt(1));
      out.println(rs.getString(2));
      }
      }
      catch(Exception e)
      {
      out.println(e);
      }
      finally {
      out.close();
      }
      }

        • 1. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
          jschellSomeoneStoleMyAlias
          You need a driver jar and it needs to be in your class path.
          • 2. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
            Joe Weinstein-Oracle
            I see two problems: First, you capitalized oracle in the driver class name. Second, you are using
            a long obsolete class name. The 'driver' part needs to be removed. Try:

            "oracle.jdbc.OracleDriver"

            Then, a third problem is that you never close the connection. You should always do so.
            • 3. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
              supratim
              Joe Weinstein wrote:
              The 'driver' part needs to be removed.
              The oracle.jdbc.driver contains a OracleDriver and the one that you are referring[oracle.jdbc.OracleDriver] simply extends it.

              package oracle.jdbc;
              public class OracleDriver extends oracle.jdbc.driver.OracleDriver
              {
              }

              so, oracle.jdbc.driver.OracleDriver also can be used without any problem. The error is the package is "oracle.jdbc.driver" not "Oracle.jdbc.driver" or
              "oracle.jdbc" not "Oracle.jdbc".
              • 4. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
                supratim
                jschell wrote:
                You need a driver jar and it needs to be in your class path.
                I would like to add something to this. If you are using the class in a web application, make sure you copy the odbc.jar file in the /WEB-INF/lib directory.
                • 5. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
                  gimbal2
                  supratim wrote:
                  jschell wrote:
                  You need a driver jar and it needs to be in your class path.
                  I would like to add something to this. If you are using the class in a web application, make sure you copy the odbc.jar file in the /WEB-INF/lib directory.
                  That depends on how you configure connections to be constructed. If you use a datasource provided by the container (which is recommended) you copy the library to the container shared library folder in stead.
                  • 6. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
                    supratim
                    gimbal2 wrote:
                    supratim wrote:
                    jschell wrote:
                    You need a driver jar and it needs to be in your class path.
                    I would like to add something to this. If you are using the class in a web application, make sure you copy the odbc.jar file in the /WEB-INF/lib directory.
                    That depends on how you configure connections to be constructed. If you use a datasource provided by the container (which is recommended) you copy the library to the container shared library folder in stead.
                    right... i am just referring the the method, 871390 is using to do the connection, in that case the copying of jar may be an issue.
                    • 7. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
                      Joe Weinstein-Oracle
                      supratim wrote:
                      Joe Weinstein wrote:
                      The 'driver' part needs to be removed.
                      The oracle.jdbc.driver contains a OracleDriver and the one that you are referring[oracle.jdbc.OracleDriver] simply extends it.

                      package oracle.jdbc;
                      public class OracleDriver extends oracle.jdbc.driver.OracleDriver
                      {
                      }

                      so, oracle.jdbc.driver.OracleDriver also can be used without any problem. The error is the package is "oracle.jdbc.driver" not "Oracle.jdbc.driver" or
                      "oracle.jdbc" not "Oracle.jdbc".
                      http://forums.oracle.com/forums/ann.jspa?annID=201

                      *"The Oracle JDBC drivers will no longer support the use of the package oracle.jdbc.driver in*
                      *future releases. Oracle JDBC 10.2 is the last release to support such package.*
                      *If your code uses any class in this package it will not compile or run with the Oracle JDBC drivers. Please replace all references to classes in the package oracle.jdbc.driver with references to the identically named class or interface in the package oracle.jdbc.*
                      *If there is no corresponding type in oracle.jdbc then you will need to use a standard J2SE type.*
                      *The classes in the package oracle.jdbc.driver will no longer be visible in the Oracle JDBC drivers. See Metalink Note 335754.1 for more details."*
                      • 8. Re: error java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver
                        supratim
                        Joe Weinstein wrote:
                        supratim wrote:
                        Joe Weinstein wrote:
                        The 'driver' part needs to be removed.
                        The oracle.jdbc.driver contains a OracleDriver and the one that you are referring[oracle.jdbc.OracleDriver] simply extends it.

                        package oracle.jdbc;
                        public class OracleDriver extends oracle.jdbc.driver.OracleDriver
                        {
                        }

                        so, oracle.jdbc.driver.OracleDriver also can be used without any problem. The error is the package is "oracle.jdbc.driver" not "Oracle.jdbc.driver" or
                        "oracle.jdbc" not "Oracle.jdbc".
                        http://forums.oracle.com/forums/ann.jspa?annID=201

                        *"The Oracle JDBC drivers will no longer support the use of the package oracle.jdbc.driver in*
                        *future releases. Oracle JDBC 10.2 is the last release to support such package.*
                        *If your code uses any class in this package it will not compile or run with the Oracle JDBC drivers. Please replace all references to classes in the package oracle.jdbc.driver with references to the identically named class or interface in the package oracle.jdbc.*
                        *If there is no corresponding type in oracle.jdbc then you will need to use a standard J2SE type.*
                        *The classes in the package oracle.jdbc.driver will no longer be visible in the Oracle JDBC drivers. See Metalink Note 335754.1 for more details."*
                        now this is some useful information..thanks joe.