在JBoss应用程序中使用MySQL ReplicationDriver的ClassCastException?

时间:2010-09-16 16:43:49

标签: sql jboss

任何人都可以帮我吗?我已阅读http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-replication-connection.html并使用

创建了一个JBoss数据源
<connection-url>jdbc:mysql:replication://sys1:3306,sys2:3306,sys3:3306/mydb</connection-url>
<driver-class>com.mysql.jdbc.ReplicationDriver</driver-class>

在我的JBoss代码中,当我执行以下命令时(在从属节点上)

Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup( ... );
conn = ds.getConnection();
conn.setReadOnly( false );
conn.prepareStatement( ... );

prepareStatement调用产生以下堆栈跟踪:

2010-09-16 18:45:31,129 WARN  [org.jboss.resource.connectionmanager.TxConnectionManager] (ajp-127.0.0.1-8009-2) Connection error occured: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1b576f8[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@11a3ce4 handles=1 lastUse=1284659131129 permit=true trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@193a581 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@56e1fe xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@f058a txSync=null]
java.lang.ClassCastException: $Proxy297
    at com.mysql.jdbc.ReplicationConnection.prepareStatement(ReplicationConnection.java:357)
    at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:465)
    at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:460)
    at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:243)
    at com.mycode.service.Kernel.doGet(Kernel.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:436)
    at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:384)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)

我四处寻找答案但找不到有类似问题的人。我错过了明显的???

由于

2 个答案:

答案 0 :(得分:1)

我们找到了解决方案! 看来,它来自mysql驱动程序: mysql-connector-java-5.1.12会出现问题,但mysql-connector-java-5.1.22不会出现问题。

所以,UPGRADE!

答案 1 :(得分:0)

堆栈跟踪似乎暗示在调用conn.prepareStatement()时发生了ClassCastException,但由于你没有将参数复制到你的问题中,我无法告诉你问题是什么。