码迷,mamicode.com
首页 > 数据库 > 详细

java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Date

时间:2017-11-21 14:32:46      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:catalina   text   mob   filter   detail   byte   value   can   oge   

架构使用jsp+servlet+java+mysql

mysql里time字段类型为datetime

java实体类中该字段类型为Date

页面中,时间字段类型为空的信息显示不出来,且报错信息如下:

java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Date
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
	at com.mysql.jdbc.ResultSet.getDateFromBytes(ResultSet.java:2304)
	at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:2052)
	at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:2015)
	at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:2069)
	at dao.impl.DevicesDaoImpl.findAll(DevicesDaoImpl.java:26)
	at service.impl.DevicesServiceImpl.findAll(DevicesServiceImpl.java:20)
	at servlet.DevicesList.doGet(DevicesList.java:31)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at filter.EncodingFilter.doFilter(EncodingFilter.java:29)

 检查代码,并没有发现什么问题,只是因为这一条数据中,这个时间字段为空而已,而数据库中此字段是可以为空的

很显然,搜了一大堆没用的文章出来。也尝试改了很多。例如,在jsp页面<%=new SimpleDateFormat("yyyy-HH-mm").format(mobile.getMarketTime())%>

最终报错信息改成这样了:

java.lang.NullPointerException
	at java.util.Calendar.setTime(Unknown Source)
	at java.text.SimpleDateFormat.format(Unknown Source)
	at java.text.SimpleDateFormat.format(Unknown Source)
	at java.text.DateFormat.format(Unknown Source)
	at org.apache.jsp.info_jsp._jspService(info_jsp.java:200)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)
	at servlet.DevicesList.doGet(DevicesList.java:33)

 不放弃,继续找

http://blog.csdn.net/dczjzz/article/details/52446901 感谢作者,帮忙解决了问题,另外他出淤泥而不染,肯定是自己搞定的

技术分享图片

解决了!

 

java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Date

标签:catalina   text   mob   filter   detail   byte   value   can   oge   

原文地址:http://www.cnblogs.com/sincoolvip/p/7872471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!