3 Replies Latest reply on Mar 1, 2010 1:01 PM by Lekan Omotayo

    Class.forName("net.sourceforge.jtds.jdbc.Driver") called inside spring

    Lekan Omotayo Expert

      Hi,

       

      I am using the com.mchange.v2.c3p0.ComboPooledDataSource library to create datasource to manage database connection.

       

      However, whenever I tried to use the datasource to get a connection it throws classnotfoundexception for net.sourceforge.jtds.jdbc.Driver. I was able to load same class (Class.forName("net.sourceforge.jtds.jdbc.Driver")) inside my bean (the one that is suppose to use the datasource connection).

       

      And I have the package of "net.sourceforge.jtds.jdbc" in my application OSGi meta info of Import-Packages.

       

      How do I resolve this?

       

      kr.

       

      Edited by: lekkie on Feb 28, 2010 1:42 AM

        • 1. Re: Class.forName("net.sourceforge.jtds.jdbc.Driver") called inside spring
          Gert Vanthienen Novice

          L.S.,

           

          We would have to see a full stacktrace for the Exception you're seeing to be absolutely sure, but most likely it's not your bundle but the datasource implementation bundle that does not have a dynamic import or something to resolve the JDBC driver class.

           

          You can fix this by using another, more OSGi-aware DataSource implementation bundle (so it can load the class from another bundle) or by using the DataSource implementation provided by the jTDS bundle itself (because it is in the same bundle as the JDBC driver, it will definitely be able to access the Driver class.  For the latter solution, the JDBC DataSource provided by the jTDS driver jar is called net.sourceforge.jtds.jdbcx.JtdsDataSource.

           

          Regards,

           

          Gert

          • 2. Re: Class.forName("net.sourceforge.jtds.jdbc.Driver") called inside spring
            Daffy Duck Novice

            Hi Gert,

             

            I encounter the exact same issue using C3P0. Below is the stacktrace exception:

             

             

            18:00:35,615 | WARN  | er$PoolThread-#0 | DriverManagerDataSource          | org.apache.log4j.Category         846 | Could not load driverClass org.postgresql.Driver

            java.lang.ClassNotFoundException: org.postgresql.Driver

                 at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)

                 at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)

                 at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)

                 at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)

                 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

                 at java.lang.Class.forName0(Native Method)

                 at java.lang.Class.forName(Class.java:169)

                 at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)

                 at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)

                 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

                 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

                 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

                 at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

                 at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

                 at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

                 at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

             

             

            If I switch from C3P0 to DBCP then it works. Is there some magical stuff in DBCP? The only way to make C3P0 work is to manually modify its MANIFEST to add the JDBC driver's package. Definitely not a thing I want to do.

             

            Are we condemned to use DBCP with OSGi?

             

            Thanks.

             

            CM

            • 3. Re: Class.forName("net.sourceforge.jtds.jdbc.Driver") called inside spring
              Lekan Omotayo Expert

              Find below the complete stacktrace:

               

              18:42:20,812 | WARN  | er$PoolThread-#0 | DriverManagerDataSource          | 14logging.Jdk14MLog$Jdk14MLogger  148 | Could not load driverClass net.sourceforge.jtds.jdbc.Driver

              java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)

                   at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)

                   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

                   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

                   at java.lang.Class.forName0(Native Method)

                   at java.lang.Class.forName(Class.java:164)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

                   at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

                   at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

                   at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

                   at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

                   at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

              18:42:20,812 | WARN  | er$PoolThread-#2 | DriverManagerDataSource          | 14logging.Jdk14MLog$Jdk14MLogger  148 | Could not load driverClass net.sourceforge.jtds.jdbc.Driver

              java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)

                   at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)

                   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

                   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

                   at java.lang.Class.forName0(Native Method)

                   at java.lang.Class.forName(Class.java:164)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

                   at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

                   at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

                   at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

                   at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

                   at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

              18:42:20,812 | WARN  | er$PoolThread-#1 | DriverManagerDataSource          | 14logging.Jdk14MLog$Jdk14MLogger  148 | Could not load driverClass net.sourceforge.jtds.jdbc.Driver

              java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)

                   at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)

                   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

                   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

                   at java.lang.Class.forName0(Native Method)

                   at java.lang.Class.forName(Class.java:164)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

                   at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

                   at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

                   at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

                   at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

                   at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

              18:42:20,812 | INFO  | oLogger-thread-1 | AbstractPoolBackedDataSource     | 14logging.Jdk14MLog$Jdk14MLogger  318 | Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1bqoogj877ftrul1updllo

              18:42:21,813 | WARN  | er$PoolThread-#0 | DriverManagerDataSource          | 14logging.Jdk14MLog$Jdk14MLogger  148 | Could not load driverClass net.sourceforge.jtds.jdbc.Driver

              java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)

                   at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)

                   at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)

                   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

                   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

                   at java.lang.Class.forName0(Native Method)

                   at java.lang.Class.forName(Class.java:164)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)

                   at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

                   at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

                   at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

                   at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

                   at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

                   at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

                   at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

              18:42:21,813 | WARN  | er$PoolThread-#2 | DriverManagerDataSource          | 14logging.Jdk14MLog$Jdk14MLogger