As I did say in a previous email chain when you asked this question, the DBCP 
BasicDataSource does things that are fundamentally not going to work in OSGi.

When you pass BasicDataSource a driver class name it is going to do something 
like:

    Class.forName(suppliedDbDriverClassName);


This will attempt to load the Driver class reflectively using the class loader 
of the DBCP bundle *not* the bundle that you’ve written. You can do as much to 
your own bundle manifest as you like and it won’t make a difference because 
DBCP is the one failing to load the driver.

When you write the code yourself I imagine that you’re directly referencing the 
class by calling something like:

    DriverManager.register(new org.h2.Driver());

or even just instantiating it as a blueprint bean directly. This creates a 
dependency from your code on the org.h2 package. Your build tool sees this and 
makes sure that the manifest is set up appropriately, hence it works.

As Christian and I have both said previously, if you want to do this properly 
in OSGi you should really be using a DataSourceFactory service to create your 
Driver/DataSource.

Then, once you have your Driver/DataSource you need to configure it using the 
DBCP *advanced* setup, not the BasicDataSource. Given that this seems to be 
causing you a lot of problems, have you considered using an alternative, for 
example HikariCP? Note that you will still need to inject a dataSource, not 
supply a class name.

Regards,

Tim


> On 5 Jul 2017, at 08:26, smunro <stephen.ross.mu...@gmail.com> wrote:
> 
> The problem with the data source approach is that I got it working with h2 in
> the past, but I have never managed to get it working for sqlserver/jtds. I
> tried the jtds feature but never got it to work. After various attempts I
> was told to just get it working via plain Java, which I can understand as
> I've been trying for a few weeks now with little success. I've not tried the
> fragment approach as I am out of time for adding extras. I just need the
> minimum working and can revisit it later on.
> 
> 
> 
> --
> View this message in context: 
> http://karaf.922171.n3.nabble.com/DBCP2-Karaf-tp4050942p4050952.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to