Select * from SQLite TempTable不能正常工作



我有这一小段代码,范围是:在外面的时候:我计算一个"分钟";number(从tempTable中选择)在内部while中:Select * from (tempTable) where(某些条件)"(我完全确定有超过1行匹配这些条件),然后我更新所选每一行的最小值(在其他方面不相关)

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),所以如果有一些拼写错误或其他东西,那不是问题。请关注ResultSet select * from TEMP_TABLE(我没有改变)

事先感谢您所提供的任何帮助。

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

最新更新