0
private void SubmitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        try
        {
        Statement s = con.createStatement();
        Statement s1 = con.createStatement();
        Statement s2 = con.createStatement();
        Statement s3 = con.createStatement();
                
        ResultSet rs = s.executeQuery("select MAX(Guest_ID) from Guests");
        rs.next();
       int maxGuestID = rs.getInt(1) + 1;
       //s1.execute("insert into Guests values(" + maxGuestID + ",'" + txtUserName.getText() + "',' " + txtUserAddress.getText() + "','"+ txtUserPhone.getText() + "','"+ txtUserEmail.getText() + "','" + cmbCreditCardType.getSelectedItem() + "','"+ txtCreditCardNumber.getText() + "')");

        // insert data into reservation table
        ResultSet rs1 = s2.executeQuery("select MAX(Reservation_ID) from Reservation");
       rs1.next();
       int maxResID = rs1.getInt(1) + 1;
  //i'm getting error for date     
       s3.execute("insert into Reservation values(" + maxResID + "," + maxGuestID +",'"+ChkPrepaid.getSelectedObjects()+",'"+txtCheckInDate.getText()+"','"+txtCheckOutDate.getText()+ "'");
       
       
        }
        catch(Exception e)
        {
                    System.out.println("Error: " + e);
        }

Edited by nav33n: Please use [code] tags to wrap your code for easy readability. P.S. Post your question.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by baki100
0

You print your failing query string on screen.
Copy it and execute in mysql query browser or phphmyadmin or msql prompt directly. There you will find the actual problem.

System.out.println("insert into Reservation values(" + maxResID + "," + maxGuestID +",'"+ChkPrepaid.getSelectedObjects()+",'"+txtCheckInDate.getText()+"','"+txtCheckOutDate.getText()+ "'");
0

i suggest building the sql query or non-query so that when it fails you can print the query and check whats happening, its usually a problem with the way the query is built.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.