FAQ(64):java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
程序员文章站
2022-04-21 15:36:51
...
1、场景:springmvc+spring 实现功能
2、Log:
java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
com.mysql.jdbc.ResultSet.getDateFromString(ResultSet.java:1886)
com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5083)
com.mysql.jdbc.ResultSet.getString(ResultSet.java:4961)
com.User.Dao.UserDaoImpl.getUserList(UserDaoImpl.java:106)
com.User.Service.UserServiceImpl.getUserList(UserServiceImpl.java:26)
com.User.Controller.UserController.getUserList(UserController.java:121)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
解决:
1、后查资料发现 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但 java.sql.Date 将其视为 不合法的值 格式不正确;
2、将带“0000-00-00 00:00:00”的记录删除了;之后的查询错误消失;
3、更好的解决方法还需要继续跟踪;
推荐阅读
-
解决:java.sql.SQLException:Value ‘0000-00-00‘ can not be represented as java.sql.Date
-
java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp异常
-
FAQ(60):java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
-
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Tim 异常解决办法
-
FAQ(64):java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
-
java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date(已解决)
-
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp at
-
java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
-
java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
-
java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp异常