4 Replies Latest reply: Feb 25, 2009 5:15 AM by a s RSS

DataSource binding to org.jboss.resource.adapter.jdbc.Wrappe

a s Newbie

Hello

i'm trying to migrate a webapp from tomcat 4.x to JBoss 5.0.0.GA but got stuck with the DataSources, the webapp uses two of them, both are mySql-Databases, though i created a mysql-ds.xml and put it into the deploy-directory, than edited the web.xml of the webapp and added a jboss-web.xml both in the WEB-INF folder of the webapp.

I hope it is a config error, because since it is not my webapp i cannot change the code.

the webapp is an exploded war wich i put under an deploy.last in the deploy folder of the server.

but i get the following error when starting the server:

...
Caused by: java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to javax.sql.DataSource
...


the mysql-ds.xml
<?xml version="1.0" encoding="UTF-8"?>

<datasources>
 <local-tx-datasource>
 <jndi-name>jdbc/ProdDataSource</jndi-name>
 <connection-url>jdbc:mysql://localhost:3306/mydb?characterEncoding=utf-8&autoReconnect=true
 </connection-url>
 <use-java-context>true</use-java-context>
 <driver-class>com.mysql.jdbc.Driver</driver-class>
 <user-name>***</user-name>
 <password>***</password>
 <max-pool-size>10</max-pool-size>
 <check-valid-connection-sql>
 select CID from COMMON_ASSET where CID=1000
 </check-valid-connection-sql>

 <metadata>
 <type-mapping>mySQL</type-mapping>
 </metadata>

 </local-tx-datasource>
</datasources>


web.xml
<?xml version="1.0" encoding="ISO-8859-15"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">
<resource-ref>
 <res-ref-name>java:jdbc/ProdDataSource</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
 <res-ref-name>java:jdbc/LiveDataSource</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>
...
</web-app>


jboss-web.xml
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
<jboss-web>
<resource-ref>
 <res-ref-name>jdbc/ProdDataSource</res-ref-name>
 <jndi-name>java:jdbc/ProdDataSource</jndi-name>
</resource-ref>
<resource-ref>
 <res-ref-name>jdbc/LiveDataSource</res-ref-name>
 <jndi-name>java:jdbc/LiveDataSource</jndi-name>
</resource-ref>
</jboss-web>


and the corresponding code snippet
...
Context initContext = new InitialContext();
Context appContext = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)appContext.lookup(datasourceName);
...


if someone could tell me what i'm doing wrong, that would be really nice.

  • 1. Re: DataSource binding to org.jboss.resource.adapter.jdbc.Wr
    a s Newbie

    sorry wrong config file, it must be
    mysql-ds.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <datasources>
     <local-tx-datasource>
     <jndi-name>jdbc/ProdDataSource</jndi-name>
     <connection-url>jdbc:mysql://localhost:3306/mydb?characterEncoding=utf-8&autoReconnect=true
     </connection-url>
     <use-java-context>true</use-java-context>
     <driver-class>com.mysql.jdbc.Driver</driver-class>
     <user-name>***</user-name>
     <password>***</password>
     <max-pool-size>10</max-pool-size>
     <check-valid-connection-sql>
     select CID from COMMON_ASSET where CID=1000
     </check-valid-connection-sql>
    
     <metadata>
     <type-mapping>mySQL</type-mapping>
     </metadata>
    
     </local-tx-datasource>
    
     <local-tx-datasource>
     <jndi-name>jdbc/LiveDataSource</jndi-name>
     <connection-url>jdbc:mysql://localhost:3306/mydb2?characterEncoding=utf-8&autoReconnect=true
     </connection-url>
     <use-java-context>true</use-java-context>
     <driver-class>com.mysql.jdbc.Driver</driver-class>
     <user-name>***</user-name>
     <password>***</password>
     <max-pool-size>10</max-pool-size>
     <check-valid-connection-sql>
     select CID from COMMON_ASSET where CID=1000
     </check-valid-connection-sql>
    
     <metadata>
     <type-mapping>mySQL</type-mapping>
     </metadata>
    
     </local-tx-datasource>
    
    </datasources>
    


    but that didn't solve the problem, still the same error

  • 2. Re: DataSource binding to org.jboss.resource.adapter.jdbc.Wr
    Peter Johnson Master

    Where did you place the JDBC driver JAR file? It should be placed in the server/xxx/lib directory. I suspect that it is in the WAR file in the WEB-INF/lib directory, in which case you need to move it out of there.

  • 3. Re: DataSource binding to org.jboss.resource.adapter.jdbc.Wr
    a s Newbie

    thanks for the reply, peter

    and indeed i had the mysql-connector in the web-inf/lib and deleted it there. now it is in server/standard/lib but i still get the same exception

    do you have any other suggestions what it might be?

  • 4. Re: DataSource binding to org.jboss.resource.adapter.jdbc.Wr
    a s Newbie

    found the error, in the webapp was another jdbc-driver, copied it to server/standard/lib and everything went fine, thanks for the help