How can I resolve this "cannot be excluded" exception?

I am getting the following exception:

java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingStatement cannot be cast to org.apache.tomcat.dbcp.dbcp.DelegatingStatement
    optimise.database.ProdigyDB.doInsertSerial(ProdigyDB.java:139)
    optimise.stock.CurrentRequest.writeRequest(CurrentRequest.java:145)
    optimise.stock.SubmitOrderServlet.processRequest(SubmitOrderServlet.java:51)
    optimise.stock.SubmitOrderServlet.doPost(SubmitOrderServlet.java:188)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    optimise.stock.AuthFilter.doFilter(AuthFilter.java:69)

      

The line of code is this:

 serial = ((com.informix.jdbc.IfmxStatement) ((org.apache.tomcat.dbcp.dbcp.DelegatingStatement) statement).getDelegate()).getSerial();

      

Full function:

public static int doInsertSerial(String sql) {
    int serial = 0;

    try {
        Connection connection = getConnection();
        java.sql.Statement statement = connection.createStatement();
        statement.executeUpdate(sql);

        serial = ((com.informix.jdbc.IfmxStatement)((org.apache.tomcat.dbcp.dbcp.DelegatingStatement) statement).getDelegate()).getSerial();

        statement.close();
        connection.close();
    } catch (SQLException e) {
        throw new RuntimeException("SQL Update Exception\n" + sql, e);                
    }

    return serial;
}

      

This is cryptic because the same code works fine when deployed on a Unix SCO5 server, but on a Red Hat Linux server.

Any help is greatly appreciated.

Thank.


Looking a little deeper into things, I can see that the DelegatingStatement class is showing an error:

Public class DelegatingStatement extends AbandonedTrace implements Statement {

org.apache.commons.dbcp.DelegatingStatement is not abstract and does not override the abstract isPoolable () method in java.sql.Statement

I don't understand why this is happening.

+3


source to share


1 answer


java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingStatement cannot be cast org.apache.tomcat.dbcp.dbcp.DelegatingStatement

The package is different for the DelegatingStatement class. org.apache.commons.dbcp

and org.apache.tomcat.dbcp.dbcp

are two different packages providing two different DelegatingStatement classes. You get a ClassCastException because the JVM doesn't see them as the same type at all.



Check out the DelegatingStatement package that is being imported. The package org.apache.tomcat.dbcp.dbcp

should be imported according to the code .

Also check this and this one

+3


source







All Articles