9 Replies Latest reply on Jan 22, 2014 4:18 AM by bharadwaj

    Datasource Setup

    gvanstad

      Good day.

       

      Can someone please help me with my datasource setup.

      I've essentially lost 2 days trying to get database connectivity.

       

      I'm trying to deploy an OSGI bundle into FUSE ESB 4 that retrieves a sql resultset from a database.

       

      The problem is that Fuse/ServiceMix does not load the jdbc driver dependency specified in my pom.xml and subsequently fails to load the driver-class.

       

      Please help. I need to get this running asap:

       

      Here's my bundle-context-xml:

       

       

      and here's the exception:

       

      Error creating bean with name 'mysqlDS' defined in URL bundle://233.0:0/META-INF/spring/bundle-context.xml: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:

      PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

           at java.security.AccessController.doPrivileged(Native Method)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)

           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)

           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)

           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)

           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)

           at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)

           ... 20 more

        • 1. Re: Datasource Setup
          stlewis

          Here, this thread should help.  The problem you are hitting is that your bundle can't see the MySQL driver.  You could either add the MySQL classes to the Import-Package directive or use DynamicImport-Header.

          • 2. Re: Datasource Setup
            gvanstad

            Thank you VERY much.

             

            Problem fixed.

            • 3. Re: Datasource Setup
              gvanstad

              OK, this works for MySQL bit NOT for Oracle.

               

              When pointing my existing code to an oracle database I get 2 problems

               

                   

               

              results in:  java.sql.SQLException: No suitable driver

               

              and

               

               

                   

               

              results in : ClassNotFoundEsception : oracle.jdbc.driver.OracleDriver

               

              Any ideas why an oracle connection would fail the way it does while a MySQL connection works perfectly?

              • 4. Re: Datasource Setup
                gvanstad

                ?

                • 5. Re: Datasource Setup
                  stlewis

                  how did you install the oracle driver into the ESB?  Can you do packages/exports for the generated bundle and see if it's exporting the Oracle packages?

                  • 6. Re: Datasource Setup
                    chan_oy@hotmail.com

                    I am getting the same problem. I am using fuse esb 4.2 and installed the following bundles,

                     

                    1.) com.springsource.com.mysql.jdbc-5.1.6.jar

                    2.) com.springsource.oracle.jdbc-10.2.0.2.jar

                    3.) org.apache.servicemix.bundles.commons-dbcp-1.2.2_5.jar (I have re-packaged the jar to have the Manifest to include DynamicImport-Package: *)

                     

                    I can connect to mysql database no problem with this code,

                     

                     

                     

                    Here's the exception I get,

                     

                    Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'j

                    dbc:oracle:thin@localhost:testdb'

                    org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '

                    oracle.jdbc.OracleDriver' for connect URL 'jdbc:oracle:thin@localhost:testdb'

                            at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou

                    rce.java:1163)

                            at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource

                    .java:881)

                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.

                    java:39)

                    ...

                    Caused by: java.sql.SQLException: No suitable driver

                            at java.sql.DriverManager.getDriver(DriverManager.java:243)

                            at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou

                    rce.java:1155)

                     

                    Any ideas why Oracle connection fails?

                    • 7. Re: Datasource Setup
                      njiang

                      Hi,

                       

                      Did you clean up the fuse ESB data directory before you install the repacked org.apache.servicemix.bundles.commons-dbcp-1.2.2_5.jar?

                      BTW, Where did you update the dbcp jar?

                      $ESB_HOME/system ... or your maven repo.

                      • 8. Re: Datasource Setup

                        Hi,

                         

                        Please upgrade your ESB version to 4.3.0-fuse-01-00. That has got the fix for https://issues.apache.org/activemq/browse/CAMEL-2909

                        • 9. Re: Datasource Setup
                          bharadwaj

                          Solution for org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' :

                           

                           

                          Step1:

                           

                           

                                  <servicemix.osgi.dynamic.import>*</servicemix.osgi.dynamic.import>

                               

                                                  <DynamicImportPackage>${servicemix.osgi.dynamic.import</DynamicImport-Package>

                                                  <Private-Package>${servicemix.osgi.private}</Private-Package>

                                              </instructions>-

                                          </configuration>

                                      </plugin>

                                  </plugins>

                              </build>

                           

                          Edited by: bharadwaj2012 on Jan 22, 2014 9:12 AM

                           

                          Edited by: bharadwaj2012 on Jan 22, 2014 9:13 AM

                           

                          Edited by: bharadwaj2012 on Jan 22, 2014 9:18 AM