Quantcast

C3P0 cannot load Jtds Driver in OSGi env

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

C3P0 cannot load Jtds Driver in OSGi env

raad
 So i have wrapped the Jtds and c3p0 jars under install wrap command and I still get the following when connection is being established:


13:37:14,941 | WARN  | er$PoolThread-#1 | DriverManagerDataSource          | 268 - com.mchange.v2.c3p0 - 0.9.1.2 | Could not load driverClass net.sourceforge.jtds.jdbc.Driver
java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver not found by com.mchange.v2.c3p0 [268]
        at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
        at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)



I've looked for blogs with similar issues but they refer to manifest changes that need to happen.  I import all the packages needed in the pom:  hereis what I have:

                        <Import-Package>
                                 ...
                        net.sourceforge.jtds.jdbc,
                        net.sourceforge.jtds.jdbcx,
              com.mchange.v2.c3p0,
                            *
                        </Import-Package>


anyone?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

C3P0 cannot load Jtds Driver in OSGi env

RubyTuesdayDONO
raad,

i'm not sure this is directly related to camel, but it looks like you're
using a DriverManager-based connection pool within an OSGi environment.  i
haven't used c3p0 before, but i do use Apache Commons DBCP and had a
similar issue with class loading problems.  i believe i tracked it down to
a call to Class.forName, which doesn't usually work nicely in OSGi.

my solution was to subclass the connection pool and directly reference the
driver class (e.g., make a JtdsDataSource).

not the most elegant solution, but it worked for me.

~ Reuben

On Wednesday, March 28, 2012, raad wrote:

>  So i have wrapped the Jtds and c3p0 jars under install wrap command and I
> still get the following when connection is being established:
>
>
> 13:37:14,941 | WARN  | er$PoolThread-#1 | DriverManagerDataSource
>  | 268 - com.mchange.v2.c3p0 - 0.9.1.2 | Could not load
> driverClass net.sourceforge.jtds.jdbc.Driver
> java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver not
> found
> by com.mchange.v2.c3p0 [268]
>
>  at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
>        at
> org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: C3P0 cannot load Jtds Driver in OSGi env

Sven Zethelius
We ran into similar issues (DBCP as well).  Our solution was to create a bundle that embedded (Bundle-Classpath) JTDS and DBCP into a single bundle so that they shared classpath.  From there you can export the necessary packages so any other bundle may create the DataSource/Connection instances in the JDBC standard way since they are now in a single classloader.

JDBC standard isn't well suited to OSGI.  OSGI Enterprise spec has a DataSourceFactory to help address this, that unfortunately very few implementations exist or integrate with.

-----Original Message-----
From: Reuben Garrett [mailto:[hidden email]]
Sent: Wednesday, March 28, 2012 11:37 AM
To: [hidden email]
Subject: C3P0 cannot load Jtds Driver in OSGi env

raad,

i'm not sure this is directly related to camel, but it looks like you're using a DriverManager-based connection pool within an OSGi environment.  i haven't used c3p0 before, but i do use Apache Commons DBCP and had a similar issue with class loading problems.  i believe i tracked it down to a call to Class.forName, which doesn't usually work nicely in OSGi.

my solution was to subclass the connection pool and directly reference the driver class (e.g., make a JtdsDataSource).

not the most elegant solution, but it worked for me.

~ Reuben

On Wednesday, March 28, 2012, raad wrote:

>  So i have wrapped the Jtds and c3p0 jars under install wrap command
> and I still get the following when connection is being established:
>
>
> 13:37:14,941 | WARN  | er$PoolThread-#1 | DriverManagerDataSource  |
> 268 - com.mchange.v2.c3p0 - 0.9.1.2 | Could not load driverClass
> net.sourceforge.jtds.jdbc.Driver
> java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver not
> found by com.mchange.v2.c3p0 [268]
>
>  at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
>        at
> org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: C3P0 cannot load Jtds Driver in OSGi env

raad
Thanks Sven.  I've seen the issue in several blogs.  I appreciate the response.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: C3P0 cannot load Jtds Driver in OSGi env

raad
In reply to this post by RubyTuesdayDONO
Reuben, I chose your method and it worked fine.  Thanks for the response.
But I do like the idea of having a fractional bundle where the dbcp and the jdbc driver live in the same classpath.

Again thank for responding.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: C3P0 cannot load Jtds Driver in OSGi env

RubyTuesdayDONO
glad it worked for you!

Sven's example sounds more elegant and robust for a larger scenario, but
it's pushing the boundaries of my current skill level.  i'll revisit once
i've learned more.

~ Reuben

On Thu, Mar 29, 2012 at 12:02, raad <[hidden email]> wrote:

> Reuben, I chose your method and it worked fine.  Thanks for the response.
> But I do like the idea of having a fractional bundle where the dbcp and
> the jdbc driver live in the same classpath.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: C3P0 cannot load Jtds Driver in OSGi env

PAC Kieffer Guillaume
Hi,

I have the same need with Informix db on Servicemix environmemt.

I chose DBCP because an OSGi version was available:
org.apache.servicemix.bundles
org.apache.servicemix.bundles.commons-dbcp
1.4_2

It worked nicely until now with a ConnectionFactory service.. And should work not only on Servicemix..
Maybe your problem is only linked to the dbcp library which was not designed to work on an OSGi environment.

Regards,
Guillaume.

ame case with had no issue with Informix drie

-----Original Message-----
From: Reuben Garrett [mailto:[hidden email]]
Sent: Thursday, March 29, 2012 19:09
To: [hidden email]
Subject: Re: C3P0 cannot load Jtds Driver in OSGi env

glad it worked for you!

Sven's example sounds more elegant and robust for a larger scenario, but
it's pushing the boundaries of my current skill level.  i'll revisit once
i've learned more.

~ Reuben

On Thu, Mar 29, 2012 at 12:02, raad <[hidden email]> wrote:

> Reuben, I chose your method and it worked fine.  Thanks for the response.
> But I do like the idea of having a fractional bundle where the dbcp and
> the jdbc driver live in the same classpath.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: C3P0 cannot load Jtds Driver in OSGi env

raad
Hey,

Once I saw servicemix had its own bundle of the commons-dbcp.  I switched it and the thing started to work like as it should.

Much appreciated for listing out that artifact.


Loading...