sql-serverjdbcdatasourcewebsphere-libertyserver.xml

WSJdbcConnection does not wrap any objects of type com.microsoft.sqlserver.jdbc.SQLServerConnection


I am using SQLServerBulkCopy API to store millions of records in SQL Server database. I get an error stating

"com.microsoft.sqlserver.jdbc.SQLServerException: Destination connection must be a connection from Microsoft JDBC Driver for SQL Server"

during initializing it like

SQLServerBulkCopy bulkCopy =  new SQLServerBulkCopy(conn);

So I unwrapped the connection

SQLServerConnection conn = connection.unwrap(SQLServerConnection.class);

The original connection is com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@8da2f3e2

After going over the following questions previously asked
1. WSJDBCConnection does not wrap objects of type Oracle jdbc Connection
2. I get the `DSRA9122E: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@d3t7e556 does not wrap any objects of type oracle.jdbc.OracleConnection

I found that it is because of classLoader for sqljdbc42.jar, mismatch between datasource and the application

So I changed my server.xml like this

 <library id="global">
   <fileset dir="${server.config.dir}/lib/global" includes="*.jar"/>
 </library>

 <jdbcDriver id="SqlJdbcDriver"              
                javax.sql.DataSource = 
 "com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource"
                 libraryRef="global"/>

 <application id="myApp" name="myApp" type="ear" location="myApp.ear">
   <classloader commonLibraryRef="global"/>
 </application>

The datasource tag resides in another server.xml that is specific for env by env -

<dataSource id="myDS" jdbcDriverRef="SqlJdbcDriver" jndiName="jdbc/myDS">
    <connectionManager agedTimeout="2m" connectionTimeout="2s" maxPoolSize="50" minPoolSize="0" />
    <properties.microsoft.sqlserver databaseName="myDB" serverName="xxx.com" /> 
</dataSource>

The sqljdbc42.jar also resides in lib/global dir.
Also, I removed the dropins dir and placed the myApp in apps dir, as the application tag will not work if the app the present in dropins dir.

After all these changes too, I get the exception

"com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@8155ea2d does not wrap any objects of type com.microsoft.sqlserver.jdbc.SQLServerConnection."

Can anybody figure out what's the solution or what still I am missing?


Solution

  • The JDBC wrapper pattern, java.sql.Wrapper.unwrap(c), is for unwrapping as interface classes only, not concrete implementation classes.

    com.microsoft.sqlserver.jdbc.SQLServerConnection is an implementation, but fortunately, the Microsoft JDBC Driver also provides an interface for it: com.microsoft.sqlserver.jdbc.ISQLServerConnection.

    Try unwrapping as the interface,

    ISQLServerConnection conn = connection.unwrap(ISQLServerConnection.class);