PreparedStatement.setObject(int i,Object obj) 无效的列类型

当往下面的方法传递参数时,传入了java.util.Date类型,因此报错
“无效的列类型”,需要把java.util.Date转换为java.sql.Date

query("select distinct bm.n_bh BH,bm.c_mc MC,bm.n_zgbmbh PARENT,bm.n_zgjcybh,bm.n_xssx from v_ywzc_wsjcjg v,t_zzjg_bm bm where v.cbbm=bm.n_bh and v.cbdw=? and v.jarq BETWEEN ? AND ? order by bm.n_xssx",new Object[]{new Long(dwbh),date1,date2});


public List query(final String sql,final Object[] params){

return (List)getJdbcTemplate().execute(sql, new PreparedStatementCallback(){
public Object doInPreparedStatement(PreparedStatement pst) throws SQLException{
if(log.isDebugEnabled()){
log.debug(sql);
}

//pst.execute(sql);
if(params!=null && params.length>0){
for(int i=1;i<=params.length;i++){
pst.setObject(i,params[i-1]);
}
}
ResultSet rs = pst.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
List l = new ArrayList();
while(rs.next()){
Map m = new HashMap();
for(int i=1;i<=colCount;i++){
m.put(rsmd.getColumnName(i),rs.getObject(i));
}
l.add(m);
}
return l;
}
});
}

==========原因============================================
Class oracle.jdbc.driver.OraclePreparedStatement

setObject(int paramIndex,Object x) throws SQLException

Sets the value of the designated parameter with the given object. This method is like setObject above, except that it finds out the SQL type base on the given object's type.

Parameters:
parameterIndex - the first parameter is 1, the second is 2, ...
x - the object containing the input parameter value
targetSqlType - the SQL type (as defined in [color=red]java.sql.Types[/color]) to be sent to the database
Throws: SQLException
if a database access error occurs
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值