0

Im struggling with debugging why my program stop in specific line, I have tried to understand if its a problem with the creation of the table or the statement but the console doesn't give me any error and still the program just stuck after running this function:

 @FXML
    private void loadIssueOperation(ActionEvent event) {
        String memberID = memberIdInput.getText();
        String bookID = bookIdInput.getText();

        Alert confAlert = new Alert(Alert.AlertType.CONFIRMATION);
        confAlert.setTitle("Confirm New Opperation");
        confAlert.setHeaderText(null);
//TASK1 
        confAlert.setContentText("Are you sure about issue the book "+bookName.getText()+
                "\n to "+memberName.getText()+"?");

        Optional<ButtonType> response = confAlert.showAndWait();
        if(response.get()==ButtonType.OK){
            String insertStr = "INSERT INTO ISSUE(memberID,bookID) VALUES("
                    + "'" + memberID + "',"
                    + "'" + bookID + "')";
            String updateStr = "UPDATE BOOK SET isAvail = false WHERE id = '"+bookID+"'";
            System.out.println(insertStr+" and "+updateStr);

            if(dataBaseHandler.execAction(insertStr) && dataBaseHandler.execAction(updateStr)){
                    Alert successAlert = new Alert(Alert.AlertType.INFORMATION);
                    successAlert.setTitle("Success");
                    successAlert.setHeaderText(null);
                    successAlert.setContentText("Complete");
                    successAlert.showAndWait();
                }else{
                    Alert failedAlert = new Alert(Alert.AlertType.ERROR);
                    failedAlert.setTitle("Failed");
                    failedAlert.setHeaderText(null);
                    failedAlert.setContentText("Issue Operation Failed");
                    failedAlert.showAndWait();
                }
        }else{
            Alert cancelAlert = new Alert(Alert.AlertType.INFORMATION);
            cancelAlert.setTitle("Canceled");
            cancelAlert.setHeaderText(null);
            cancelAlert.setContentText("Issue Operation Canceled");
            cancelAlert.showAndWait();
        }
    }

the table which i tried to insert and update is this:

 void setupIssueTable(){
       String TABLE_NAME="ISSUE";
       try {
           stmt = conn.createStatement();
           DatabaseMetaData dbm = conn.getMetaData();
           ResultSet tables = dbm.getTables(null, null, TABLE_NAME.toUpperCase(), null);
           if(tables.next()){
               System.out.println("Table "+ TABLE_NAME + "Already exist, ready for go!");
           }else{
               stmt.execute("CREATE TABLE "+ TABLE_NAME + "("
               + "       bookID varchar(200) primary key,\n"
               + "       memberID varchar(200),\n"
               + "       issueTime timestamp default CURRENT_TIMESTAMP,\n"
               + "       renew_Count integer default 0,\n"
               + "       FOREIGN KEY (bookID) REFERENCES BOOK(id),\n"
               + "       FOREIGN KEY (memberID) REFERENCES MEMBER(id)\n"
               + " )");
           }

       } catch (SQLException e) {
           System.err.println(e.getMessage()+".......setupDatabase");
       }finally{
       }
   }

is there any problem with the code? I'm new to java

naor ohayon
  • 319
  • 2
  • 8

0 Answers0