db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Newell" <Chris.New...@xelorsoftware.com>
Subject select count(*) == ClassCastException:CountAggregator
Date Wed, 01 Mar 2006 22:34:08 GMT
Hello all...

 

I seem to have resolved my own issue as I was preparing a message to
this list seeking help (thanks!). Having spent more hours than I care to
admit trying to figure this out, and having seen another user in the
list archive that had a similar problem with no solution provided, I
thought that I'd post this with hopes of helping someone else that made
the same stupid mistake.

 

The issue was previously discussed in December:

http://mail-archives.apache.org/mod_mbox/db-derby-user/200512.mbox/%3c43
96CF07.7000508@mgrinformatica.com.br%3e

 

The problem was: 

-------------------------

This issue arises when executing the statement "select count(*) from
DEFAULT_SCHEMA.general_events". If I execute it using a datasource from
the Tomcat pool I got the exception: 'java.lang.ClassCastException:
org.apache.derby.impl.sql.execute.CountAggregator' was thrown while
evaluating an expression. When I execute nearly identical code loading
the driver myself I got a proper response.

 

The environment was:

------------------------------

RedHat 4ES/2.6.9-5.EL

Apache Tomcat/5.5.7

Apache Derby/10.1.2.1

 

The code was:

---------------------

This worked:

            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

            Connection xconn =
DriverManager.getConnection("jdbc:derby:xag;create=true");

            Statement xstmnt = xconn.createStatement();

            if (xstmnt.execute("select count(*) from
DEFAULT_SCHEMA.general_events")){   

                ResultSet xrs = xstmnt.getResultSet();

                if (xrs.next()){

                    int xxx = xrs.getInt(1);

                }

            }

 

This didn't work:

            InitialContext cxt = new InitialContext();

            DataSource ds = (DataSource)
cxt.lookup("java:comp/env/xag/derby");

            Connection conn = ds.getConnection();

            Statement stmnt = conn.createStatement();

            if (stmnt.execute("select count(*) from
DEFAULT_SCHEMA.general_events")){   

                ResultSet rs = stmnt.getResultSet();

                if (rs.next()){

                    int xx = rs.getInt(1);

                }

            }

 

The exception was:

----------------------------

SQL Exception: The exception 'java.lang.ClassCastException:
org.apache.derby.impl.sql.execute.CountAggregator' was thrown while
evaluating an expression.

 

The solution was:

-------------------------

I found that I had put a copy of derby.jar in both $TOMCAT/common/lib as
well as $TOMCAT/webapps/[my app]/WEB-INF/lib. I removed the one under
webapps and suddenly, as if by magic, I could count the rows in my
table.... And the world seems like a nicer place.

 

 

 

 


Mime
View raw message