0

I have a tableView in JavaFX (for recording attendance of students) which has a column of checkBox (called "attendance") which can be checked by user. My database has a column called "classesAttended" which stores total no. of classes attended by students.

My approach is:

Database Table name: "student"

Database Column Name: "classesAttended"

TableView Column Name: "attendance"


    {

    TableView<Student> tables = new TableView<Student>();

    TableColumn<Student, Boolean> attendance = new TableColumn<Student,Boolean>();
    }

    String query="UPDATE student SET classesAttended = classesAttended+1";

    pst = conn.prepareStatement(query);

    for(TableRow tableRow: tables.getRows()){ 

        string input =    tables.get(i).getAttendanceColumn().toString();        

        if(input = "true"){

            pst.execute;

        }

    }

So I want to increment the value of "classesAttended" for student whose "attendance" column is checked. Please suggest me how can I do it.......

Thanks in Advance

  • Your code contains some syntax errors. Why do you use the string version of the `Boolean` though? You should consider yourself lucky that `Boolean` uses literal strings for it's `toString` method and comparing therefore the result refers to the same object as `"true"`. (see https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) You shouldn't rely on this in general, especially if you could simply use `if (tables.get(i).getAttendanceColumn())` – fabian Nov 13 '18 at 13:46

1 Answers1

0

You need a where clause in the query to match the row on the tableView to the record in the database.

Gnas
  • 698
  • 1
  • 6
  • 14