2 Replies Latest reply on Nov 7, 2014 12:45 PM by marci Wilken

    Cannot load JDBC driver class

    marci Wilken Newbie

      I've been working through Christina's Homeloan demo for Fuse 6.1 in anticipation of move our current system from 4.6 to 6.1(big change between the two)

      I've gotten it to work except for the issues with getting the JDBC connection to my database up and running on ESB.  

       

      The message I get two errors

      The first when I start the project

       

      Could not refresh JMS Connection for destination 'customer' - retrying in 5000 ms. Cause: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect

       

      And the second when I try to save the data to the database.

       

      Failed delivery for (MessageId: queue_customer_ID____________-62836-1415321625775-7_1_1_1_1 on ExchangeId: ID-DHSCT1082884-62834-1415321624921-1-1). Exhausted after delivery attempt: 1 caught: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'

       

      The demo uses postgres but since I don't have that, I've been attempting to connect to our SqlServer DBs.  The project works correctly and saves the data when I do a camel:run so I know the underlying routes are good.  So it has to be in the packaging and configuration of what I deploy to the server.


      Here is what I hope is the relevant data and someone can see where I when wrong.


      In the blueprint  customerinfo.xml

       

      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

            <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>

            <property name="url" value="jdbc:sqlserver://training-warehouse:1433;DatabaseName=test"/>

            <property name="username" value="test"/>

            <property name="password" value="test"/>

          </bean>

      <!-- configure the Camel SQL component to use the JDBC data source -->

          <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">

            <property name="dataSource" ref="dataSource"/>

          </bean>   


      in the pom.xml


        <properties>

          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

          <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

          <fabric8.parentProfiles>feature-camel</fabric8.parentProfiles>

          <fabric8.profile>gettingstarted</fabric8.profile>

            <fabric8.bundles>wrap:mvn:com.microsoft.sqlserver/sqljdbc4/4.0  mvn:commons-dbcp/commons-dbcp/1.4</fabric8.bundles>

          <fabric8.features> war camel-cxf cxf camel-http4 camel-jaxb camel-sql camel-jackson</fabric8.features>

          <fabric8.featureRepos>mvn:org.apache.camel.karaf/apache-camel/${version:camel}/xml/features</fabric8.featureRepos>

        </properties>

       

        <dependency>  

              <groupId>com.microsoft.sqlserver</groupId>  

              <artifactId>sqljdbc4</artifactId>  

              <version>4.0</version> 

          </dependency> 

       

      This was my latest attempt.

      <plugin>

              <groupId>org.apache.felix</groupId>

              <artifactId>maven-bundle-plugin</artifactId>

              <version>2.3.7</version>

              <extensions>true</extensions>

              <configuration>

                <instructions>

                  <Bundle-SymbolicName>homeloan</Bundle-SymbolicName>

                  <Private-Package>org.blogdemo.homeloan.*</Private-Package>

             <!--       <Import-Package>oft.postgresql,*</Import-Package> -->

                         <_exportcontents>org.microsoft.sqlserver.*</_exportcontents>   <--- I added this -->

                  <Import-Package>*</Import-Package>

                </instructions>

              </configuration>

            </plugin>

       

      I found sqldbc4-4.0.jar C:\JBoss\Fuse\jboss-fuse-6.1.0.redhat-379\instances\demoContainer but evidently this isn't in the class path not sure where to go from here

        • 1. Re: Cannot load JDBC driver class
          bharadwaj n Novice

          org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'

           

          Solution :

          Add property :

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

              

          add dynamic imports:

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

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

                              </instructions>-

                          </configuration>

                      </plugin>

                  </plugins>

              </build>

           

          javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect


          solution : make sure you enable JASS  user name and password under etc/user.properties.

          admin=admin,admin.

          • 2. Re: Cannot load JDBC driver class
            marci Wilken Newbie

            This worked much thanks,  I'm not sure exactly why though.  I read this article http://wso2.com/library/tutorials/develop-osgi-bundles-using-maven-bundle-plugin/ which give a pretty good over view of the import, export and private  but doesn't say a lot about the Dynamic.  I'm also not sure why something like <Import-Package>com.microsoft.sqlserver,*</Import-Package>. For anyone that comes across this issue. Here is what I ended up with.

            to install the driver

            mvn install:install-file -X -Dfile=C:\dev\homeloan\3rdParty\sqljdbc_4.0\enu\sqljdbc4.jar -Dpackaging=jar  -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0

             

             

              <properties>

                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

                <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

                <fabric8.parentProfiles>feature-camel</fabric8.parentProfiles>

                <fabric8.profile>gettingstarted</fabric8.profile>

            <!--      <fabric8.bundles>wrap:mvn:postgresql/postgresql/9.0-801.jdbc4 mvn:commons-dbcp/commons-dbcp/1.4</fabric8.bundles> --> 

                  <fabric8.bundles>wrap:mvn:com.microsoft.sqlserver/sqljdbc4/4.0  mvn:commons-dbcp/commons-dbcp/1.4</fabric8.bundles>

                <fabric8.features> war camel-cxf cxf camel-http4 camel-jaxb camel-sql camel-jackson</fabric8.features>

                <fabric8.featureRepos>mvn:org.apache.camel.karaf/apache-camel/${version:camel}/xml/features</fabric8.featureRepos>

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

              </properties>

             

             

            <dependency>  

                    <groupId>com.microsoft.sqlserver</groupId>  

                    <artifactId>sqljdbc4</artifactId>  

                    <version>4.0</version> 

                

                </dependency> 

             

            <!-- to generate the MANIFEST-FILE of the bundle -->

                  <plugin>

                    <groupId>org.apache.felix</groupId>

                    <artifactId>maven-bundle-plugin</artifactId>

                    <version>2.3.7</version>

                    <extensions>true</extensions>

                    <configuration>

                      <instructions>

                        <Bundle-SymbolicName>homeloan</Bundle-SymbolicName>

                        <Private-Package>org.blogdemo.homeloan.*</Private-Package>

                   <!--       <Import-Package>oft.postgresql,*</Import-Package> -->

                       <!--          <_exportcontents>org.microsoft.sqlserver.*</_exportcontents> -->

                      

                          <Import-Package>*</Import-Package>

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

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

                      </instructions>

                    </configuration>

                  </plugin>