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

架构使用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 感谢作者,帮忙解决了问题,另外他出淤泥而不染,肯定是自己搞定的

解决了!

 

转载于:https://www.cnblogs.com/sincoolvip/p/7872471.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值