0

I created class to handle the database implementation. and I build javafx GUI. One of the button supposed to store the data into the database. With know I use the same data base to login so the issue is not with the database connection.

the database implementation:

        Connection conn =null;
        String dbuser = "root";
        String dbpassw = "0557724289";
        String databasename = "java_cinemaTickets";
        String url = "jdbc:mysql://127.0.0.1:3306/java_cinemaTickets";
        String driver = "com.mysql.jdbc.Driver";
        PreparedStatement ps;

public void addMovie_insetIntoDB(String title,String description,String cinema,String time,int threator,String movie_uniqeID,String image) throws ClassNotFoundException, SQLException{

     Class.forName(driver);
        conn = DriverManager.getConnection(url,dbuser,dbpassw);
        Statement st = conn.createStatement();

        ps = conn.prepareStatement("insert into movie(movie_name,description,time,threator,mviUniqeID,movie_poster,catgory,age)"+"values(?,?,?,?,?,?,?,?,?)");

       ps.setString(1, title);
       ps.setString(2, description);
       ps.setString(3, cinema);
       ps.setString(4, time);
       ps.setInt(5, threator);
       ps.setString(6, movie_uniqeID);
       ps.setString(7, image);



       ps.executeQuery();

       conn.close();

}

Then in the another class:

String movieName_String = movieNameToAdd_textField.getText();
    String movieDescription_String = MovieDescriptionToAdd_textArea.getText();
    String moviePoster_string= "rr";//moviePoster_textField.getText();
    String cinemaLocation_string = cinemaToAdd_comboBox.getSelectionModel().getSelectedItem().toString();
    String movieTime_string = timeToAdd_comboBox.getSelectionModel().getSelectedItem().toString();
    int  movieThretor_integer = Integer.parseInt(threatorToAdd_comboBox.getSelectionModel().getSelectedItem().toString());
    String movieUniQID="jj";



    adminAddMovie_button.setOnAction(e->{


        try {
            db.addMovie_insetIntoDB(movieName_String,movieDescription_String,cinemaLocation_string,movieTime_string,movieThretor_integer,movieUniQID,moviePoster_string);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Java_CinemaTicket.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Java_CinemaTicket.class.getName()).log(Level.SEVERE, null, ex);
        }

    primaryStage.setTitle("Admin GUI");
    primaryStage.setScene(admin_Scene);
    primaryStage.show();

    });

Error I receive once I press the button to save the data into the database

Dec 02, 2016 9:00:55 PM java_cinematicket.Java_CinemaTicket lambda$start$2
SEVERE: null
java.sql.SQLException: Can not issue data manipulation statements with      executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:504)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2223)
at java_cinematicket.JavaMongoDBConnection.addMovie_insetIntoDB(JavaMongoDBConnection.java:95)
at java_cinematicket.Java_CinemaTicket.lambda$start$2(Java_CinemaTicket.java:479)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937) 
2
  • @Simze nope I checked already Commented Dec 2, 2016 at 13:17
  • 4
    You haven't because you're using ps.executeQuery(); to execute insert statement! Commented Dec 2, 2016 at 13:19

1 Answer 1

1

AFAIK you need to use executeUpdate() for DML operations (insert/update/delete) and not executeQuery().

Look and read the exception message carefully, it's saying exactly the same thing here java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.