NutzCN Logo
问答 插入时候报错Data truncation: Out of range
发布于 2494天前 作者 qq_2ac473ac 3087 次浏览 复制 上一个帖子 下一个帖子
标签:

nutz自动建的表,插入数据的时候报错

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Out of range value for column 'total' at row 1
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
	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)
	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:252)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:148)
	at com.qcjy.kotya.service.ManuscriptService.addManuscript(ManuscriptService.java:49)
	at com.qcjy.kotya.module.ManuscriptModule.addManuscript(ManuscriptModule.java:79)
	at com.qcjy.kotya.module.ManuscriptModule$FM$addManuscript$f469a1796036a6cd03d77b6003c3309a.invoke(ManuscriptModule.java)
manuscript.setPrice((double)Math.round(manuscript.getPrice()*100)/100);
		if(manuscript.getTotal()==null) {
			Double total=(int)manuscript.getQuantity()*((double)manuscript.getPrice());
			manuscript.setTotal(total);
		}

前台传过的是5445*54,算出来30W不到,怎么会Out of range啊

	@Column
	private Integer quantity;
	@Column
	private Double price;
	@Column
	private Double total;	
6 回复

@Wizzercn

CREATE TABLE `manuscript` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `Manuscriptname` varchar(128) NOT NULL,
  `cusid` int(32) DEFAULT NULL,
  `ManuscriptType` int(32) DEFAULT NULL,
  `unit` int(32) DEFAULT NULL,
  `quantity` int(32) DEFAULT NULL,
  `price` decimal(15,10) DEFAULT NULL,
  `total` decimal(15,10) DEFAULT NULL,
  `revdate` varchar(128) DEFAULT NULL,
  `deadline` varchar(128) DEFAULT NULL,
  `actualdate` varchar(128) DEFAULT NULL,
  `reciverid` int(32) DEFAULT NULL,
  `ct` datetime DEFAULT NULL,
  `ut` datetime DEFAULT NULL,
  `state` int(32) DEFAULT NULL,
  `isforin` int(32) DEFAULT NULL,
  `updater` int(32) DEFAULT NULL,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `Manuscriptname` (`Manuscriptname`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;

Json.toJson(manuscript) 打印出来,然后一对比~

后台应该打印了sql插入语句的

就是字段宽度不够,我改成float就可以了。。

	@Column
	@ColDefine(type=ColType.FLOAT)
	private Float price;
	@Column
	@ColDefine(type=ColType.FLOAT)
	private Float total;
添加回复
请先登陆
回到顶部