Java 根据另一个表中选定的输出更新另一个表中的行,但程序仅更新最上面的一行

Java 根据另一个表中选定的输出更新另一个表中的行,但程序仅更新最上面的一行,java,android-studio,jdbc,sql-update,rows,Java,Android Studio,Jdbc,Sql Update,Rows,我想根据表“BRTR”中选定的行更新表“WORKTR”中的多行。不幸的是,该程序仅基于“BRTR”表中最上面的一行更新WORKTR表 这是我的密码: Button Back = (Button) findViewById(R.id.btn_back); Back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(Vi

我想根据表“BRTR”中选定的行更新表“WORKTR”中的多行。不幸的是,该程序仅基于“BRTR”表中最上面的一行更新WORKTR表

这是我的密码:

      Button Back = (Button) findViewById(R.id.btn_back);
        Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                connectionClass = new ConnectionClass();
                Connection con = connectionClass.CONN();
                try {
                    final String PIC = lblname.getText().toString();
                    String dates = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
                    String check = "Select * from BRTR where work_date='" + dates + "' and end_break is null";
                    Statement st = con.createStatement();

                    rs = st.executeQuery(check);


                    while (rs.next()) {
                        String PF_NO = rs.getString("PF_No");



                        String query2 = "Update WORKTR set status ='" + b_status + "' where Start_date='" + dates + "' and Pf_no='" + PF_NO + "' and Scan_by='" + PIC + "' and status='" + a_status + "'";

                        st.executeUpdate(query2);
                    }
                } catch (Exception ex)
                {

                }
                onBackPressed();
            }

        });

如果您发现上述代码中有任何错误,请提供帮助或通知。

尝试使用另一条语句,因为
st.executeUpdate(query2)
将关闭结果集,您将获得
JdbcSQLException
,但是您将忽略代码中的所有异常。您至少应该将
ex.printStackTrace()
放在catch块中,以便查看发生了什么

尽管在代码方面还有很多需要改进的地方,但从功能上来说,这应该适合您

      Button Back = (Button) findViewById(R.id.btn_back);
    Back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            connectionClass = new ConnectionClass();
            Connection con = connectionClass.CONN();
            try {
                final String PIC = lblname.getText().toString();
                String dates = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
                String check = "Select * from BRTR where work_date='" + dates + "' and end_break is null";
                Statement st = con.createStatement();

                rs = st.executeQuery(check);


                while (rs.next()) {
                    String PF_NO = rs.getString("PF_No");



                    String query2 = "Update WORKTR set status ='" + b_status + "' where Start_date='" + dates + "' and Pf_no='" + PF_NO + "' and Scan_by='" + PIC + "' and status='" + a_status + "'";

                    con.createStatement().executeUpdate(query2);
                }
            } catch (Exception ex)
            {
               ex.printStackTrace(); // now we can see what is going wrong
            }
            onBackPressed();
        }

    });