I have a bundle which is using mySQL.jdbc.driver , I have given the dependency in pom file,import-packages and copied mysql connector in lib, deploy folder , installed mysql driver using install wrap:mvn:mysql/mysql-connector-java/5.1.17, i mean I did all possible as per me, but still I am getting error message as under, FYI I am using karaf-4.0.0.M2, please help its road block for me,
errorMessage = JDBC driver name is missing or not valid, cause = java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by portframeworkservice [this is my bundle name]
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by portframeworkservice [145]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
Database drivers in OSGi are always a bit difficult as the most common approach outside OSGi using DriverManager is not really suitable for OSGi.
The best approach in OSGi is to use a DataSourceFactory which is standardized by the OSGi alliance. Some database drivers already offer this. For others pax-jdbc provides an adapter. For mysql the second case applies.
So my advice is to use pax-jdbc like this:
If you then do
So the feature offers you a ready to use DataSourceFactory. You can bind it as an OSGi service and create a DataSource from it. To make it even more convenient you can also use pax-jdbc-config and pax-jdbc-pool to create a ready to use pooled DataSource as a service.
I have a complete tutorial for accessing databases in OSGi that shows this approach.