JDBC DataSource or XADataSource cannot be cast to java.sql.Driver in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6
- 7
Issue
-
Encountering an error using
DB2SimpleDataSource... IJ000610: Unable to fill pool: javax.resource.ResourceException: Could not create connection ... Caused by: javax.resource.ResourceException: Failed to register driver for: com.ibm.db2.jcc.DB2SimpleDataSource ... Caused by: java.lang.ClassCastException: com.ibm.db2.jcc.DB2SimpleDataSource cannot be cast to java.sql.Driver ...
Resolution
It may be helpful to review the use of DataSource, XADataSource and Driver implementations for JDBC access in JBoss EAP for context on the discussion below.
-
If using only
xa-datasourceuse only thexa-datasource-classproperty.- Note that the class specified using the
<xa-datasource-class>property must implement the Content from docs.oracle.com is not included.javax.sql.XADataSource interface.
- Note that the class specified using the
-
If configuring a (non-XA)
datasourceomit both<driver-class>and<datasource-class>specification where possible. -
If it is not possible to omit both
<driver-class>and<datasource-class>class, use one of the following approaches:3.1. For the
<driver-class>property, specify a class which implements the Content from docs.oracle.com is not included.java.sql.Driver interface.
3.2. If no appropriate implementation of theDriverinterface exists, specify a class which implements the Content from docs.oracle.com is not included.javax.sql.DataSource interface using the<datasource-class>property instead of<driver-class>. -
When required, it is recommended that the
<driver-class>OR<datasource-class>and/or<xa-datasource-class>properties be specified within a<driver>entry in the<drivers>configuration rather than replicating the relevant property in each<datasource>...</datasource>or<xa-datasource>...</xa-datasource>specification.
Root Cause
One of the following is likely to be the source of the failure:
-
In the driver configuration, a datasource or XA datasource class was specified as the
<driver-class>:<driver name="db2" module="com.db2.jdbc"> <driver-class>com.ibm.db2.jcc.DB2SimpleDataSource</driver-class> <!-- This is incorrect --> </driver> -
In the non-XA datasource configuration, a datasource or XA datasource class was specified as the
<driver-class>:<driver-class>com.ibm.db2.jcc.DB2SimpleDataSource</driver-class> <!-- This is incorrect -->
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.