0

I can't figure out why the executeQuery method is throwing an exception, I tried running statement on mysql and it works correctly.

Here is the code:

 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...
 }

Here is the trace:

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) at business.BusinessDelegate.handleRequest(BusinessDelegate.java:35) at presentation.command.InserisciOperatore.Execute(InserisciOperatore.java:25) at presentation.ApplicationController.handleRequest(ApplicationController.java:183) at 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(Unknown Source) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source) at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(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) at javafx.event.Event.fireEvent(Unknown Source) at javafx.scene.Node.fireEvent(Unknown Source) at javafx.scene.control.Button.fire(Unknown Source) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source) at com.sun.javafx.scene.control.skin.BehaviorSkinBase1ドル.handle(Unknown Source) at com.sun.javafx.scene.control.skin.BehaviorSkinBase1ドル.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) at javafx.event.Event.fireEvent(Unknown Source) at javafx.scene.Scene$MouseHandler.process(Unknown Source) at javafx.scene.Scene$MouseHandler.access1500ドル(Unknown Source) at javafx.scene.Scene.impl_processMouseEvent(Unknown Source) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source) 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$handleMouseEvent354ドル(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$null148ドル(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: 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 more

Mark Rotteveel
110k241 gold badges160 silver badges233 bronze badges
asked Feb 26, 2016 at 19:41
10
  • 3
    print the stack trace Commented Feb 26, 2016 at 19:42
  • statement.executeUpdate()==1 What does this do ? Commented Feb 26, 2016 at 19:44
  • sorry, forget the "==1" Commented Feb 26, 2016 at 19:45
  • Should not the above code be as int count = statement.executeUpdate(); In the second part you can check if (count >0) then the db was successfully update Commented Feb 26, 2016 at 19:46
  • Do you still have the problem? Commented Feb 26, 2016 at 19:48

2 Answers 2

1

If you want to check if statement.executeUpdate() is 1 you need to put it in if statement.

try {
 if (statement.executeUpdate() == 1) {
 // do something
 }
 else {
 // do something else
 }
}
catch (SQLException e) {
 throw new ExecuteQueryException(); //throws this...
}
Rahul Tripathi
173k33 gold badges292 silver badges341 bronze badges
answered Feb 26, 2016 at 19:43
Sign up to request clarification or add additional context in comments.

1 Comment

sorry, forget the "==1"
0

I solved the problem, it was a wrong type error.

answered Feb 27, 2016 at 11:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.