从tableview checkbox javafx将数据插入数据库

y1aodyip  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(385)

我在javafx中有一个tableview(用于记录学生的出勤情况),其中有一列checkbox(称为“出勤”),用户可以对其进行检查。我的数据库有一个名为“classesattended”的列,其中存储了学生上课的总数。
我的方法是:
数据库表名:“student”
数据库列名:“classesattended”
tableview列名:“考勤”

  1. {
  2. TableView<Student> tables = new TableView<Student>();
  3. TableColumn<Student, Boolean> attendance = new TableColumn<Student,Boolean>();
  4. }
  1. String query="UPDATE student SET classesAttended = classesAttended+1";
  2. pst = conn.prepareStatement(query);
  3. for(TableRow tableRow: tables.getRows()){
  4. string input = tables.get(i).getAttendanceColumn().toString();
  5. if(input = "true"){
  6. pst.execute;
  7. }
  8. }

所以我想为“出勤”列被选中的学生增加“classesattended”的值。请告诉我怎么做。。。。。。。
提前谢谢

aor9mmx1

aor9mmx11#

你需要一个 where 子句将表视图上的行与数据库中的记录相匹配。

相关问题