Encounter a problem, online find a lot of information can not solve their own curve to solve the national salvation, record, if you have a better way to welcome the message.
First I created a table on the MySQL database with the datetime type of the Createtime field (project needs my personal bias bigint after all to do sort of what is more efficient);
Then the project uses JDBC, when I use Preparestatement, Preparestatement.settimestamp (6, Qa.getcreatetime ()); Qa.getcreatetime () is a new Timestamp (New Date (). GetTime ()) Of course, it is possible to copy the SQL script in the preparestatement by Debug and execute it in Navicat. But the program is error, error message is as follows:
Save Quiz exception, exception information: java.sql.SQLException: #22007
Com.career.other.exception.OtherDataException: Save question and answer exception database operation failed!
At Com.career.sys.dao.QaDao.save (qadao.java:107)
At Com.career.sys.action.QaAction.question (qaaction.java:63)
At Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
At Sun.reflect.NativeMethodAccessorImpl.invoke (nativemethodaccessorimpl.java:62)
At Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:43)
At Java.lang.reflect.Method.invoke (method.java:498)
At OGNL. Ognlruntime.invokemethod (ognlruntime.java:873)
At OGNL. Ognlruntime.callappropriatemethod (ognlruntime.java:1539)
At OGNL. Objectmethodaccessor.callmethod (objectmethodaccessor.java:68)
At Com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo (Xworkmethodaccessor.java : 96)
At Com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod (xworkmethodaccessor.java:88)
At OGNL. Ognlruntime.callmethod (ognlruntime.java:1615)
At OGNL. Astmethod.getvaluebody (astmethod.java:91)
At OGNL. Simplenode.evaluategetvaluebody (simplenode.java:212)
At OGNL. Simplenode.getvalue (simplenode.java:258)
At OGNL. Ognl.getvalue (ognl.java:467)
At OGNL. Ognl.getvalue (ognl.java:431)
At Com.opensymphony.xwork2.ognl.ognlutil$3.execute (ognlutil.java:371)
At Com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecuteMethod (ognlutil.java:423)
At Com.opensymphony.xwork2.ognl.OgnlUtil.callMethod (ognlutil.java:369)
At Com.opensymphony.xwork2.DefaultActionInvocation.invokeAction (defaultactioninvocation.java:436)
At Com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly (defaultactioninvocation.java:291)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:252)
At Org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept (debugginginterceptor.java:253)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept (Defaultworkflowinterceptor.java : 176)
At Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept (validationinterceptor.java:260)
At Org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept ( ANNOTATIONVALIDATIONINTERCEPTOR.JAVA:52)
At Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.doIntercept (Conversionerrorinterceptor.java : 139)
At Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (parametersinterceptor.java:134)
At Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (parametersinterceptor.java:134)
At Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept (Staticparametersinterceptor.java : 199)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.interceptor.MultiselectInterceptor.intercept (multiselectinterceptor.java:69)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept (datetextfieldinterceptor.java:115)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.interceptor.CheckboxInterceptor.intercept (checkboxinterceptor.java:88)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.interceptor.FileUploadInterceptor.intercept (fileuploadinterceptor.java:246)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept (modeldriveninterceptor.java:99)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept (Scopedmodeldriveninterceptor.java : 139)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept (chaininginterceptor.java:157)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept (prepareinterceptor.java:174)
At Com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (methodfilterinterceptor.java:98)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.interceptor.I18nInterceptor.intercept (i18ninterceptor.java:123)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.interceptor.ServletConfigInterceptor.intercept (servletconfiginterceptor.java:171)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept (aliasinterceptor.java:201)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept (Exceptionmappinginterceptor.java : 193)
At Com.opensymphony.xwork2.DefaultActionInvocation.invoke (defaultactioninvocation.java:247)
At Org.apache.struts2.factory.StrutsActionProxy.execute (strutsactionproxy.java:53)
At Org.apache.struts2.dispatcher.Dispatcher.serviceAction (dispatcher.java:577)
At Org.apache.struts2.dispatcher.ExecuteOperations.executeAction (executeoperations.java:81)
At Org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter ( strutsprepareandexecutefilter.java:143)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:193)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:166)
At Com.career.sys.action.SessionFilter.doFilter (sessionfilter.java:50)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:193)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:166)
At Org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (characterencodingfilter.java:85)
At Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107)
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:198)
At Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:96)
At Org.apache.catalina.authenticator.AuthenticatorBase.invoke (authenticatorbase.java:493)
At Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:140)
At Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:81)
At Org.apache.catalina.valves.AbstractAccessLogValve.invoke (abstractaccesslogvalve.java:650)
At Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:87)
At Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:342)
At Org.apache.coyote.http11.Http11Processor.service (http11processor.java:800)
At Org.apache.coyote.AbstractProcessorLight.process (abstractprocessorlight.java:66)
At Org.apache.coyote.abstractprotocol$connectionhandler.process (abstractprotocol.java:800)
At Org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun (nioendpoint.java:1471)
At Org.apache.tomcat.util.net.SocketProcessorBase.run (socketprocessorbase.java:49)
At Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1149)
At Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:624)
At Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (taskthread.java:61)
At Java.lang.Thread.run (thread.java:748)
Very depressed!
The solution is as follows: Convert the Time field to a string and then
Preparestatement.setstring (6, Qa.getcreatetime () ==null? Null:qa.getCreateTime (). toString ()); Such a way set value, succeeded!
Record a few times, writing is not, I hope you give other more elegant way, thank you!
JDBC preparestatement Solution for error in datetime field stored on MySQL