2016-04-09 89 views
0

目前無法修復此MySQL異常。我檢查了幾個類似於我的問題,無法弄清爲什麼我的FullName列不被接受。我使用MySQL Workbench做了一個手動CALL語句,並且它完美地工作,同時試圖從Java代碼調用它,但它不喜歡它。MySQL列'FullName'不能爲空

電流誤差:

Column 'FullName' cannot be null 
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'FullName' cannot be null 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) 
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) 
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283) 
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504) 
at com.mysql.jdbc.CallableStatement.executeUpdate(CallableStatement.java:824) 
at com.jpalenci.action.RequestAction.callInsertUserData(RequestAction.java:118) 
at com.jpalenci.action.RequestAction.execute(RequestAction.java:49) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:871) 
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1294) 
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68) 
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117) 
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108) 
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1370) 
at ognl.ASTMethod.getValueBody(ASTMethod.java:90) 
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) 
at ognl.SimpleNode.getValue(SimpleNode.java:258) 
at ognl.Ognl.getValue(Ognl.java:494) 
at ognl.Ognl.getValue(Ognl.java:458) 
at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:315) 
at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:346) 
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:313) 
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:430) 
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:290) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:251) 
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:168) 
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) 
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76) 
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229) 
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229) 
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) 
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:140) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) 
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) 
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) 
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567) 
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81) 
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) 
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) 

這裏是我使用調用我的存儲過程,將數據插入我的MySQL數據庫當前的方法:

public static void callInsertUserData() throws SQLException{ 
    String insertUserData = "{CALL insertUserData(?,?,?,?,?,?)}"; 

    try{ 
     dbConn = getDBConn(); 
     callStmt = dbConn.prepareCall(insertUserData); 

     callStmt.setString(1, in_FullName); 
     callStmt.setString(2, in_PhoneNumber); 
     callStmt.setString(3, in_EmailAddress); 
     callStmt.setString(4, in_CheckOutDate); 
     callStmt.setString(5, in_DeviceUsage); 
     callStmt.setString(6, in_DeviceSelection); 

     callStmt.executeUpdate(); 

    } catch (SQLException e) { 
     System.out.println(e.getMessage()); 
     e.printStackTrace(); 
    } finally { 
     if (callStmt != null) { 
      callStmt.close(); 
     } 
    } 
} 

insertUserData存儲過程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `insertUserData`(
IN in_FullName VARCHAR(255), 
IN in_PhoneNumber VARCHAR(255), 
IN in_EmailAddress VARCHAR(255), 
IN in_CheckOutDate VARCHAR(255), 
IN in_DeviceUsage VARCHAR(255), 
IN in_DeviceSelection VARCHAR(255) 
) 
BEGIN 
    INSERT INTO devices_requested (FullName, PhoneNumber, EmailAddress, CheckOutDate, DeviceUsage, DeviceSelection) 
    VALUES (in_FullName, in_PhoneNumber, in_EmailAddress, in_CheckOutDate, in_DeviceUsage, in_DeviceSelection); 
END 

我不知道我的插入Java代碼有什麼問題。由於這是我上週創建的另一個項目的副本,也是來自學校作業的副本,所以他們都工作。難道我錯誤地傳遞了我的信息?或者可能會給我提出問題的ExecuteUpdate代碼?

編輯:我目前使用的包含數據字段。

//Data Fields That Come From User Inputted Data 
private static String in_FullName; 
private static String in_PhoneNumber; 
private static String in_EmailAddress; 
private static String in_CheckOutDate; 
private static String in_DeviceUsage; 
private static String in_DeviceSelection; 
+0

很明顯,在你的代碼中,'in_FullName'爲null。 – Zymus

+1

不可能,因爲我從未指定'in_FullName'爲空。 – RedPhanthom

+0

'callStmt.setString(1,in_FullName);'add' System.out.println(in_FullName);'之前。輸出是什麼? – Zymus

回答

0

我想出了我遇到的問題,我的getter/setter編碼不正確。我問了一個做這種Web服務的人,他們能夠弄清楚我遇到的問題。

我有我的setter/getters static,因爲他們是由eclipse自動製作的。因此,每當我做了一個插入數據的調用,它將無法從我使用的表單中獲取任何東西Struts的。