【发布时间】:2016-02-26 19:41:52
【问题描述】:
我不知道executeQuery方法为什么会抛出异常,我尝试在mysql上运行语句,它工作正常。
代码如下:
queryInserimento = "INSERT INTO operatore (Cognome, Email, Nome, Sede, Telefono, Username,Password) "
+ "VALUES ('" + cognome + "','" + email + "','" + nome + "','" + sede + "','" + telefono + "','" + username + "','"+cryptedPassword+"');";
System.out.println(queryInserimento);
try {
Connection conn=MySQLDaoFactory.initConnection();
PreparedStatement statement=conn.prepareStatement(queryInserimento);
try {
statement.executeUpdate() //Here is the problem
}
catch (SQLException e) {
throw new ExecuteQueryException(); //throws this...
}
这是踪迹:
java.lang.reflect.InvocationTargetException 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在 java.lang.reflect.Method.invoke(未知来源) 在business.BusinessDelegate.handleRequest(BusinessDelegate.java:35) 在presentation.command.InserisciOperatore.Execute(InserisciOperatore.java:25) 在presentation.ApplicationController.handleRequest(ApplicationController.java:183) 在presentation.FrontController.handleRequest(FrontController.java:35) 在presentation.ui.controller.NuovoOpController.conferma(NuovoOpController.java:85) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在 java.lang.reflect.Method.invoke(未知来源) 在 sun.reflect.misc.Trampoline.invoke(未知来源) 在 sun.reflect.GeneratedMethodAccessor1.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在 java.lang.reflect.Method.invoke(未知来源) 在 sun.reflect.misc.MethodUtil.invoke(未知来源) 在 javafx.fxml.FXMLLoader$MethodHandler.invoke(未知来源) 在 javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(未知来源) 在 com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知来源) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知来源) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventUtil.fireEventImpl(未知来源) 在 com.sun.javafx.event.EventUtil.fireEvent(未知来源) 在 javafx.event.Event.fireEvent(未知来源) 在 javafx.scene.Node.fireEvent(未知来源) 在 javafx.scene.control.Button.fire(未知来源) 在 com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(未知来源) 在 com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(未知来源) 在 com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(未知来源) 在 com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(未知来源) 在 com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(未知来源) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知来源) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知来源) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(未知来源) 在 com.sun.javafx.event.EventUtil.fireEventImpl(未知来源) 在 com.sun.javafx.event.EventUtil.fireEvent(未知来源) 在 javafx.event.Event.fireEvent(未知来源) 在 javafx.scene.Scene$MouseHandler.process(未知来源) 在 javafx.scene.Scene$MouseHandler.access$1500(未知来源) 在 javafx.scene.Scene.impl_processMouseEvent(未知来源) 在 javafx.scene.Scene$ScenePeerListener.mouseEvent(未知来源) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(未知来源) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(未知来源) 在 java.security.AccessController.doPrivileged(本机方法) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(未知来源) 在 com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(未知来源) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(未知来源) 在 com.sun.glass.ui.View.handleMouseEvent(未知来源) 在 com.sun.glass.ui.View.notifyMouse(未知来源) 在 com.sun.glass.ui.win.WinApplication._runLoop(本机方法) 在 com.sun.glass.ui.win.WinApplication.lambda$null$148(未知来源) 在 java.lang.Thread.run(未知来源) 引起:dao.mySQL.ExecuteQueryException 在 dao.mySQL.MySQLOperatoreDAO.inserisciOperatore(MySQLOperatoreDAO.java:54) 在 business.entity.OperatoreBusiness.inserisciOperatore(OperatoreBusiness.java:48) 在business.GestisciOperatore.inserisciOperatore(GestisciOperatore.java:58) ... 67 更多
【问题讨论】:
-
打印堆栈跟踪
-
statement.executeUpdate()==1这是做什么的? -
抱歉,忘记了“==1”
-
上面的代码不应该是 int count = statement.executeUpdate();在第二部分中,您可以检查 (count >0) 是否成功更新数据库
-
你还有问题吗?