2 Replies Latest reply on Jul 4, 2017 5:16 PM by martinm1000

    ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDataTable (not part of JDBC ?)

    martinm1000

      Hi,

       

      So I have an ear file under WildFly that works, but my application can't find the specific class SQLServerDataTable that is referenced in my code.

       

      I've installed the mssql driver under wildfly in modules/ and it works. The code also work in client mode.

       

      I just started using SQLServerDataTable to use SQL Table Valued Parameters, but it seems the code doesn't have access to that specific class, but I'm not sure why.

       

      I'm thinking I might need to review how I deploy the mssql jar with my application ?

       

      Currently the mssql jar and datasource is defined in standalone-full.xml by the server, and not the application.

       

      What should I do ? Can I export those classes, add a dependency somewhere ?

        • 1. Re: ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDataTable (not part of JDBC ?)
          martinm1000

          Ok, So I was able to fix the Class not found by adding to jboss-deployment-structure.xml :

           

              <deployment>

                  <dependencies>

                      <module name="com.microsoft.sqlserver"/>

                  </dependencies>

              </deployment>

           

          but I now have a wrapper problem ?

           

          org.jboss.jca.adapters.jdbc.jdk7.WrappedCallableStatementJDK7 cannot be cast to com.microsoft.sqlserver.jdbc.SQLServerCallableStatement

          • 2. Re: ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDataTable (not part of JDBC ?)
            martinm1000

            Ok, I think I found the solution to the problem, which I'll explain below for others to find.

             

            But I would like to know if there are better ways to achieve the same thing.

             

            So I needed to have code under WildFly that use Microsoft SQL Server JDBC specific classes so I can use Table Valued Parameters:

             

                 SQLServerDataTable labor = make_tyPC_RateLaborTable();

                 try (SQLServerCallableStatement cs = (SQLServerCallableStatement)conn.prepareCall(FULL_MERGE_LABOR_RATES)) {

             

            To have access to these classes, I needed to add the sqlserver module as a dependency (which I didn't have to do before since I used plain JDBC spec classes):

             

                 Added <module name="com.microsoft.sqlserver" slot="main"/> to jboss-deployment-structure.xml

             

            Next, at run-time I got to see:

                

                  org.jboss.jca.adapters.jdbc.jdk7.WrappedCallableStatementJDK7 cannot be cast to com.microsoft.sqlserver.jdbc.SQLServerCallableStatement

             

            After searching and trying a LOT of things, I found out that I needed to have the following code :

               

                 WrappedConnection wc = (WrappedConnection)connection;

                 Connection c = wc.getUnderlyingConnection();

             

            and then i would have my instance of SQLServerCallableStatement through that SQL Connection.

             

            To get the above code to compile, I found out (after hours of searching) that I needed a maven reference to:

             

                 <dependency>

                   <groupId>org.jboss.ironjacamar</groupId>

                   <artifactId>ironjacamar-jdbc</artifactId>

                   <version>1.3.4.Final</version>

                   <scope>provided</scope>

                 </dependency>

             

            Then at run-time I still got problems, and I finally found out I needed to add some other stuff to my jboss-deployment-structure.xml, as follow:

             

                 <?xml version="1.0"?>

                 <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

                     <ear-subdeployments-isolated>true</ear-subdeployments-isolated>

                     <deployment>

                         <dependencies>

                             <module name="org.jboss.ironjacamar.jdbcadapters" slot="main" export="true"/>

                             <module name="com.microsoft.sqlserver" slot="main"/>

                         </dependencies>

                     </deployment>

                 </jboss-deployment-structure>

             

            In the end, I also needed to have export to true to have it work.

             

            So is there any other safer and less crazy way to achieve this ?