Select * 来自 SQLite TempTable 的工作不正常

Select * from SQLite TempTable not working properly

我有这么一小段代码,范围是: 在外面:我计算了一个“最小”数字(select来自临时表) 在内部 while:我“Select * from (tempTable) where (some conditions)”(我完全确定有超过 1 行符合这些条件)然后我更新每行中的最小值 selected(其他方面不相关)

 The inner while is conditioned by rs.next() which (as it does in other parts of my code) it should iterate through every row that matches the condition ("Select * from (tempTable) where (some conditions)")

  Basically the program should work as: getting a "min" value, then proceed to update each row with equal "min" and "min" = "min" + 1. So in the next iteration of the outter while the "min" should be 1 more.
  Instead, what it does is: get "min" value, then update ONLY the first row that matches that min value and goes back to the outter while(which calculates the min again). In the end, the output is rather the same and it kinda works, but I would really appreciate if it worked as I intended to match other aspects of the program.
  I think the problem comes from doing a select * from a TEMPtable which for some reason returns only 1 row (i've been investigating but couldnt find other people with the same issue, so i don't really know). As I mentioned, there is other parts of my code where I do the same select * NORMALtable and the ResultSet.Next() works as intended.

while( total_tfgs > 0 ) {
        int tfgs_round = 0;
        min = prepareStatement.executeQuery("SELECT MIN("+ PROFESORES_COL_TFGS +") FROM TEMP_TABLA_PROFESORES WHERE " + PROFESORES_COL_OBLIGA + " = 'SÍ'").getInt(1);
        ResultSet rs = prepareStatement.executeQuery("SELECT * FROM TEMP_TABLA_PROFESORES WHERE " + PROFESORES_COL_TFGS + " = '" + min + "' AND " + PROFESORES_COL_OBLIGA + " = 'SÍ'");
    
        while(rs.next()) {
            prepareStatement.executeUpdate("UPDATE TEMP_TABLA_PROFESORES SET PROFESORES_COL_TFGS = PROFESORES_COL_TFGS + 1 WHERE PROFESORES_COL_ID = '" + rs.getInt(1) + "'");
            tfgs_round = tfgs_round + 1;
            
            
        }
        
        total_tfgs = total_tfgs - tfgs_ronda;
    }

在这里,我将代码放置在我希望它工作的地方:

    Statement statement = con.createStatement();
    ResultSet rsA = statement.executeQuery("SELECT * FROM " + TABLA_ALUMNOS);
    while(rsA.next()) {                
            String idA = String.valueOf(rsA.getInt("ALUMNOS_COL_ID"));
            String dniA = rsA.getString("ALUMNOS_COL_DNI");
            String nombreA = rsA.getString("ALUMNOS_COL_NOMBRE");
            
            String dataA[] = {idA, dniA, nombreA};
            DefaultTableModel tblModel = (DefaultTableModel) table_Alumnos.getModel();
            
            tblModel.addRow(dataA);
            table_Alumnos.setModel(tblModel);
    }

PD:在编辑这个时我将一些变量更改为英语(在第一个代码片段中)所以它会更清晰(tfgs_round,total_tfgs),所以如果有一些拼写错误或东西,那不是问题。请关注结果集 select * 来自 TEMP_TABLE(我没有更改)

提前感谢您提供的任何帮助。

我不会在读取 ResultSet 的循环中调用 executeUpdate。这意味着您正在将该语句用于第二个查询,而它仍涉及第一个查询。我会完全完成第一个查询,关闭 ResultSet,然后单独执行更新。如果您真的需要在读取 ResultSet 时进行更新,我会为其构建一个新语句。