java.sql.SQLException:Data truncation: Incorrect date value: 'XX' for column 'xx' at row 1 Query解决办法

最近在实现往数据库添加数据操作时出现了如下SQL异常:
java.sql.SQLException: Data truncation: Incorrect date value: 'xx' for column 'xx' at row 1 Query: insert into product values (?,?,?,?,?,?,?) Parameters: [E4F2E4DD05E2452E85F9A2E74CA4384F, xx, xx, xx, null, xx, 2018-12-23 14:10:39]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:320)
at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:489)
at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:455)
at com.java.dao.ProductDao.savePro(ProductDao.java:27)
at com.java.service.ProductService.savePro(ProductService.java:21)
at com.java.servlet.ProductServlet.add(ProductServlet.java:84)
at com.java.servlet.ProductServlet.doGet(ProductServlet.java:32)
at com.java.servlet.ProductServlet.doPost(ProductServlet.java:128)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:412)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1385)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

异常提示是截断了插入的数据,因为格式不匹配。
其原因是SQL语句出现错误:String sql=“insert into 表 values(?,?,?,?,?,?,?)”;其中问号必须和数据库中字段一一对应,不然就出现数据异常,我的后一个数据是double的,插入了一个varchar的数据就报了此异常。
修改后数据正常。

你可能感兴趣的:(Java,SQL)