1 - Don't know if this is the correct mailing list, and I don't know about C3P0, but we use proxool and OSGi/Felix and here is a snipet of code that works for us with Oracle, MySQL and MS SQL server (jtds driver) 2 - Make sure that you import the proper packages in Import-Package if your driver is not in the same bundle 3 - Oracle Driver is supposed to be in oracle.jdbc, but the Driver registers a class in oracle.jdbc.driver, so you need to import this one also (and BTW oracle.sql is required too).


Thread th = Thread.currentThread();
ClassLoader cl = th.getContextClassLoader();
try {
        // retrieve the OSGi class loader
// the current object is an instance of a class loaded by the OSGi bundle // this bundle imports the packages of the JDBC drivers with the "optional" option
        // for example: mysql: com.mysql.jdbc;resolution:=optional
        ClassLoader dbLoader = this.getClass().getClassLoader();
        th.setContextClassLoader(dbLoader);
        // load the driver for registration in DriverManager
        Class.forName(driverClassName, true, dbLoader);
        // try to get a connection
        Connection con = DriverManager.getConnection(dburl, dbuser, pass);

        // do something with the connection ...

        con.close();
 catch(SQLException e) {
        // handle the exception...
} catch (ClassNotFoundException e) {
        // handle the exception...
} finally {
        th.setContextClassLoader(cl);
}




On Dec 19, 2007, at 10:58 AM, Damian Gołda wrote:

I have question, not regarding OPS4J but you are OSGi experts ...

In many libraries, especially providing database connection pools,
there is used DriverManager for instantiation of JDBC Driver.
I can't  force DriverManager to work in OSGi - it always cannot find
class with driver. I've looked in its source code and find weird way
to find "correct" classloader, which actually is unuseful, because
doesn't use bundle classloader or context classloader.

Do you have any solutions, how to solve that problem?
Only solution working for me is to modify source code of connection
pool, to not use DriverManager. But I hate it...
I try to use C3P0.
--
Damian

_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Pierre Dubois
Requea
www.requea.com
06 82 27 46 32


_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to