commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anderson, James H [IT]" <james.h.ander...@citigroup.com>
Subject [DbUtils] ClassCastException
Date Tue, 22 Jun 2004 14:31:39 GMT
(This is a resend of a msg I sent yesterday which I did not see appear on the list. In fact,
I haven't received any mail from the list for a day or two...)

I'm getting a ClassCastException that I don't understand. I hope someone can help with this,
because I'd very much like to be able to use DbUtil on my project!

The stack trace:

org.apache.commons.dbutils.BasicRowProcessor$CaseInsensitiveHashMap
java.lang.ClassCastException: org.apache.commons.dbutils.BasicRowProcessor$CaseInsensitiveHashMap
	at com.ssmb.recom.aft.access.DbUtil.select(DbUtil.java:143)
	at com.ssmb.recom.aft.access.DbUtil.selectOneMapTrimmed(DbUtil.java:66)
	at com.ssmb.recom.aft.datamanager.AftRequests.nextBusinessDate(AftRequests.java:3454)
	at com.ssmb.recom.aft.datamanager.AftRequests.nextBusinessDateAfter(AftRequests.java:3489)
	at com.ssmb.recom.aft.datamanager.AftRequests.main(AftRequests.java:2920)

The invoking code:

        java.sql.Date sqlDate = new java.sql.Date( date.getTime() );

        String selectTradingDate = "select trading_date from trade_days where trading_date
>= ? and banking_day = 'B'";

        Object[] params = { sqlDate };
        boolean  commit = true;

        Map h = null;
        try {
            h = (Map) DbUtil.selectOneMapTrimmed(selectTradingDate, params, commit);
        } catch (Exception e) {
            logger.error("No trade date >= " + date, e);
            throw new RuntimeException(e.getMessage());
        }
        java.util.Date tradeDate = (java.util.Date) h.get("trading_date");


My wrapper code as invoked in the code, above:

package com.ssmb.recom.aft.access;

import java.sql.*;
import java.util.*;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.*;
import org.apache.commons.dbutils.wrappers.*;
import org.apache.commons.beanutils.BeanUtils;

import com.ssmb.recom.datamgr.RecomDataSource;

public class DbUtil {

[...]

	/**
	   select one row, set param=null to avoid parameter substitution
	 */
	public static Object selectOneMapTrimmed(String query, Object[] param, boolean commit)
	throws Exception {

		MapHandler h = new MapHandler() {
				public Object handle (ResultSet rs) throws SQLException {
					StringTrimmedResultSet wrapped = new StringTrimmedResultSet(rs);
					rs = ProxyFactory.instance().createResultSet(wrapped);
					Object returnVal = null;
					try {
						returnVal = super.handle(rs);
					} catch (SQLException e) {
						System.out.println(e.getMessage());
						throw e;
					}
					return returnVal;
				}
			};

		if (param == null) {
			return select(query, h, commit);
		} else {
			return select(query, param, h, commit);
		}
	}

[...]

}

The table being queried:

table              database   creator    created   
------------------ ---------- ---------- ----------
trade_days         db2tst08   vimdbat    06/20/2000

column             type     length scale nulls
------------------ -------- ------ ----- -----
trading_date       date     4      0     y    
trading_day        char     1      0     y    
trading_dow        smallint 2      0     y    
banking_day        char     1      0     y    
--------------------


Note:

When I execute this query using vanilla JDBC, everything works fine.

Any help appreciated,

jim

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message