NutzCN Logo
问答 一个查询出错,不能比较double字段吗
发布于 2814天前 作者 qq_8c799e25 1976 次浏览 复制 上一个帖子 下一个帖子
标签:

我用这样的mysql语句查询:
SELECT * FROM t_stock_day_kline WHERE DATE=20070104 AND openP<high AND isupn(pre1_close, high, 7)=1

sql执行没有问题。

然后用代码实现:

		List<StockDayKline> high_up7list = dao.query(StockDayKline.class,
				Cnd.where("date", "=", choseDate).and("openP", "<", "high").and(new Static("isupn(pre1_close, high, 7)=1")));

报错:

Exception in thread "main" org.nutz.dao.DaoException: org.nutz.castor.FailToCastObjectException: Fail to cast 'high' to <double>
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:248)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:452)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:457)
	at com.hans.stock.ban.TradeMaster.trade1HC(TradeMaster.java:249)
	at com.hans.stock.ban.TradeMaster.Trade1HC(TradeMaster.java:181)
	at com.hans.stock.ban.TradeMaster.main(TradeMaster.java:349)
Caused by: org.nutz.castor.FailToCastObjectException: Fail to cast 'high' to <double>
	at org.nutz.castor.castor.String2Number.cast(String2Number.java:45)
	at org.nutz.castor.castor.String2Number.cast(String2Number.java:19)
	at org.nutz.castor.Castors.cast(Castors.java:252)
	at org.nutz.castor.Castors.castTo(Castors.java:318)
	at org.nutz.dao.jdbc.Jdbcs$Adaptor$11.set(Jdbcs.java:508)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:269)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	... 9 more
Caused by: java.lang.NumberFormatException: For input string: "high"
	at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1250)
	at java.lang.Double.valueOf(Double.java:504)
	at org.nutz.castor.castor.String2Double.valueOf(String2Double.java:12)
	at org.nutz.castor.castor.String2Double.valueOf(String2Double.java:3)
	at org.nutz.castor.castor.String2Number.cast(String2Number.java:39)
	... 21 more

但是我去掉openP和high的比较就成功:

		List<StockDayKline> high_up7list = dao.query(StockDayKline.class,
				Cnd.where("date", "=", choseDate).and(new Static("isupn(pre1_close, high, 7)=1")));

StockDayKline类的high和openP字段都是double:

    @Column
    private double openP;
    
    @Column
    private double closeP;
    
    @Column
    private double high;

难道条件里不能比较double字段?

2 回复

这样要对比两个字段???

and(new Static("openP < high"));

// 三个参数的时候, value是值, 是值, 填另外一个字段名, 然后openP又是double, 自然转型错误.
and(key, op, value)
添加回复
请先登陆
回到顶部