我无法弄清楚为什么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 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) 在business.BusinessDelegate.handleRequest(BusinessDelegate.java:35) at presentation.command.InserisciOperatore.Execute(InserisciOperatore.java:25) at presentation.ApplicationController.handleRequest(ApplicationController.java:183) 在presentation.FrontController.handleRequest(FrontController.java:35) at presentation.ui.controller.NuovoOpController.conferma(NuovoOpController.java:85) 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 sun.reflect.misc.Trampoline.invoke(未知来源) at sun.reflect.GeneratedMethodAccessor1.invoke(未知来源) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) 在javafx.fxml.FXMLLoader $ MethodHandler.invoke(未知来源) 在javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle(未知来源) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 在javafx.event.Event.fireEvent(未知来源) 在javafx.scene.Node.fireEvent(未知来源) 在javafx.scene.control.Button.fire(未知来源) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source) at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(Unknown Source) at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(Unknown Source) at com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent(Unknown Source) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 在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(未知来源) at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(Unknown Source) at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 354(Unknown Source) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source) at com.sun.glass.ui.View.handleMouseEvent(Unknown Source) at com.sun.glass.ui.View.notifyMouse(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda $ null $ 148(未知来源) 在java.lang.Thread.run(未知来源) 引起:dao.mySQL.ExecuteQueryException at dao.mySQL.MySQLOperatoreDAO.inserisciOperatore(MySQLOperatoreDAO.java:54) at business.entity.OperatoreBusiness.inserisciOperatore(OperatoreBusiness.java:48) at business.GestisciOperatore.inserisciOperatore(GestisciOperatore.java:58) ... 67更多
答案 0 :(得分:1)
如果您想检查if
是否为1,则需要将其放入try {
if (statement.executeUpdate() == 1) {
// do something
}
else {
// do something else
}
}
catch (SQLException e) {
throw new ExecuteQueryException(); //throws this...
}
声明。
{{1}}
答案 1 :(得分:0)
我解决了这个问题,这是一个错误的类型错误。