11 Replies Latest reply: Jun 27, 2012 9:17 AM by newbieRyan RSS

    class not found exception

    newbieRyan

      I am writing a small JPA app which create table and write data, however,
      it said it didn't find class oracle.jdbc.OrcaleDriver.
      where can I find one & install it?

      [EL Info]: 2012-06-24 17:22:34.135--ServerSession(210314711)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
      [EL Severe]: 2012-06-24 17:22:34.153--ServerSession(210314711)--Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
      Exception Description: Configuration error. *Class [oracle.jdbc.OracleDriver] not found*.
      Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
      Exception Description: Configuration error. *Class [oracle.jdbc.OracleDriver] not found.*
      at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
      at com.apress.javaee6.chapter02.Main.main(Main.java:22)




      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
      http://java.sun.com/xmls/ns/persistence/persistence_2_0.xsd"
      version="2.0">

      <persistence-unit name="chapter02PU" transaction-type="RESOURCE_LOCAL">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <class>com.apress.javaee6.chapter02.Book</class>
      <Properties>
      <property name="exlipselink.target-database" value="Oracle"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
      <property name="eclipselink.logging.level" value="INFO"/>
      <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:orcale://locahost:1521/chapter02DB;create=true"/>
      <property name="javax.persistence.jdbc.user" value="mountain"/>
      <property name="javax.persistence.jdbc.password" value="ohmyGod1"/>
      </Properties>
      </persistence-unit>
      </persistence>

        • 1. Re: class not found exception
          rp0428
          Welcome to the forum!

          Here is the official Oracle JDBC page that shows the Oracle DB versions supported for each of the JDBC drivers available and also describes the JDBC jars and what JDK versions they support.
          http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#02_01

          See the question: Where can I get the class files.

          Make sure you use the JDBC driver version appropriate for your JDK and database.
          • 2. Re: class not found exception
            gimbal2
            941358 wrote:
            I am writing a small JPA app which create table and write data, however,
            it said it didn't find class oracle.jdbc.OrcaleDriver.
            where can I find one & install it?
            On the Oracle website of course.

            http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
            • 3. Re: class not found exception
              newbieRyan
              as you suggested, I placed a copy of ojdbc6.jar to /WEB-INF/lib
              it generated similar error saying unable to acqurie a connection from driver. and ask me to check persistence.xml and session.xml
              I don't have session.xml in my app. Could you point me to the right place

              [EL Info]: 2012-06-25 18:59:49.929--ServerSession(1025983099)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
              Exception in thread "main" [EL Severe]: 2012-06-25 18:59:51.423--ServerSession(1025983099)--Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
              Exception Description: *Unable to acquire a connection from driver [oracle.jdbc.OracleDriver]*, user [mountain] and URL [jdbc:orcale://locahost:1521/chapter02DB;create=true]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
              Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:orcale://locahost:1521/chapter02DB;create=true
              Error Code: 0
              javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
              Exception Description: Unable to acquire a connection from driver [oracle.jdbc.OracleDriver], user [mountain] and URL [jdbc:orcale://locahost:1521/chapter02DB;create=true]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
              Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:orcale://locahost:1521/chapter02DB;create=true
              Error Code: 0
                   at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
                   at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
                   at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
                   at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
                   at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
                   at com.apress.javaee6.chapter02.Main.main(Main.java:22)
              Caused by: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
              Exception Description: Unable to acquire a connection from driver [oracle.jdbc.OracleDriver], user [mountain] and URL [jdbc:orcale://locahost:1521/chapter02DB;create=true]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
              Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:orcale://locahost:1521/chapter02DB;create=true
              Error Code: 0
                   at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:376)
                   at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:393)
                   at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:123)
                   at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
                   at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
                   at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
                   at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
                   ... 5 more
              Caused by: java.sql.SQLException: No suitable driver found for jdbc:orcale://locahost:1521/chapter02DB;create=true
                   at java.sql.DriverManager.getConnection(DriverManager.java:604)
                   at java.sql.DriverManager.getConnection(DriverManager.java:190)
                   at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:98)
                   ... 9 more



              <?xml version="1.0" encoding="UTF-8"?>
              <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                             http://java.sun.com/xmls/ns/persistence/persistence_2_0.xsd"
                             version="2.0">
                                  
                   <persistence-unit name="chapter02PU" transaction-type="RESOURCE_LOCAL">
                        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
                        <class>com.apress.javaee6.chapter02.Book</class>
                        <Properties>
                             <property name="exlipselink.target-database" value="Orcale"/>
                             <property name="eclipselink.ddl-generation" value="create-tables"/>
                             <property name="eclipselink.logging.level" value="INFO"/>
                             <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
                             <property name="javax.persistence.jdbc.url" value="jdbc:orcale://locahost:1521/chapter02DB;create=true"/>
                             <property name="javax.persistence.jdbc.user" value="mountain"/>
                             <property name="javax.persistence.jdbc.password" value="ohmyGod1"/>
                        </Properties>
                   </persistence-unit>
              </persistence>
              • 4. Re: class not found exception
                gimbal2
                Well perhaps that is because your JDBC URL is just wrong and contains even a typo.
                • 5. Re: class not found exception
                  rp0428
                  >
                  I don't have session.xml in my app. Could you point me to the right place
                  >
                  As gimbal2 already said your url is wrong.
                  <property name="javax.persistence.jdbc.url" value="jdbc:orcale://locahost:1521/chapter02DB;create=true"/>
                  Presumably you mean 'oracle' instead of 'orcale' and 'localhost' instead of 'locahost'. And I have never seen the 'create=true' parameter used with Oracle and would be very surprised if it works. Most likely you just copied that from some example without realizing what it is used for. That might be used for Java DB or some other database.

                  And if you mean 'Oracle' then this line is wrong also
                  <property name="exlipselink.target-database" value="Orcale"/>
                  Suggest you double check all connection items, get a simple connection and code to work and then refactor your code to include your sample working connection.
                  • 6. Re: class not found exception
                    newbieRyan
                    I've checked all typo and glassfish JDBC connection pool. the ping is ok
                    thank you very much. it's one step forward.
                    I googled the oracle url. jdbc:oracle:thin:@localhost:1521:orcl
                    but it doesn't work. it complain invalid url. but i compose the URL following this example http://wiki.eclipse.org/EclipseLink/Examples/JPA/OutsideContainer


                    [EL Info]: 2012-06-26 13:24:57.066--ServerSession(766035905)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
                    [EL Severe]: 2012-06-26 13:24:57.204--ServerSession(766035905)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
                    Internal Exception: java.sql.SQLException: Invalid Oracle URL specified
                    Error Code: 17067
                    Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
                    Internal Exception: java.sql.SQLException: Invalid Oracle URL specified
                    Error Code: 17067
                         at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
                         at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
                         at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
                         at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
                         at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
                         at com.apress.javaee6.chapter02.Main.main(Main.java:22)
                    Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
                    Internal Exception: java.sql.SQLException: Invalid Oracle URL specified
                    Error Code: 17067
                         at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
                         at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
                         at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
                         at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
                         at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
                         at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
                         at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
                         ... 5 more
                    Caused by: java.sql.SQLException: Invalid Oracle URL specified
                         at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:423)
                         at java.sql.DriverManager.getConnection(DriverManager.java:579)
                         at java.sql.DriverManager.getConnection(DriverManager.java:190)
                         at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:98)
                         ... 9 more
                    • 7. Re: class not found exception
                      newbieRyan
                      Thanks very much.
                      I've fixed all error, and the app run smooth!
                      Thank again to all showing me all the tips
                      • 8. Re: class not found exception
                        rp0428
                        Glad you found the problem. Please help others that may have the same issue by posting your solution and mark the question ANSWERED.
                        • 9. Re: class not found exception
                          newbieRyan
                          for those using glassfish v3 + eclipse indigo + oracle 11g
                          the right oracle url format for javax.persistence.jdbc.url is jdbc:oracle:thin://localhost:1521:SID

                          put a copy of ojdbc6.jar in /WEB-INF/lib
                          also put persistence.xml in /WEB-INF/classes/META-INF
                          • 10. Re: class not found exception
                            gimbal2
                            941358 wrote:
                            for those using glassfish v3 + eclipse indigo + oracle 11g
                            It is not related to the application server or whatever development tool you use. Its specific to the OJDBC driver.
                            the right oracle url format for javax.persistence.jdbc.url is jdbc:oracle:thin://localhost:1521:SID
                            If you're going to make it a format its like this:

                            jdbc:oracle:thin://HOST:PORT:SID

                            Where HOST can be either the hostname or the IP address. The database is not likely going to be running on the localhost.
                            put a copy of ojdbc6.jar in /WEB-INF/lib
                            That only works if you don't use a datasource (which you should) but in stead manually configure connection properties in your persistence.xml (like you're doing). If you define a datasource in your application server, you need to put the JDBC driver jar somewhere where the application server can find it, not in your own application.
                            • 11. Re: class not found exception
                              newbieRyan
                              I did configure JDBC connection and resource on glassfish server.
                              however, when I click run on eclipse, it tries to deploy the app on server, but it always fails.
                              Therefore, I click the arrow next to the run and click main. It runs.

                              the other issue, the ojdbc6.jar, I placed it in C:\glassfish3\glassfish\lib. I did a ping in [JDBC Connection]. it's successful.
                              but, I don't know why On running the small app, it always says it can't find the oracle.jdbc.OracleDriver.
                              Could you please tell me how to fix it?