Failing to update the table based on checked value

。_饼干妹妹 提交于 2020-01-30 11:57:27

问题


I've a listview from the database with checkbox. My objectives is to insert the checked listview into a table and update another table based on the checked listview. Unfortunately, my SQL query did not work in the section.

Here is my code to insert the checked listview into BRTR table and update rows in WORKTR table based on the checked listview:

 // Get Item Checked
        Button btnGetItem = (Button) findViewById(R.id.btnGetItem);
        btnGetItem.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                int count = lisView1.getAdapter().getCount();
                for (int i = 0; i < count; i++) {
                    LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i); // Find by under LinearLayout
                    CheckBox checkbox = (CheckBox)itemLayout.findViewById(R.id.ColChk);
                    if(checkbox.isChecked()) {
                        PFNO = checkbox.getTag().toString();

                        try {
                            Connection con = connectionClass.CONN();
                            if (con == null) {
                                z = "Error in connection with SQL server";
                            } else {
                                Statement st = con.createStatement();
                                String ReasonAll = "Break-All";
                                String dates = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
                                String currentTime = DateFormat.getDateTimeInstance().format(new Date());
                                String query = "insert into BRTR (PF_No,start_break,work_date, reason_break) values('" + PFNO + "','" + currentTime + "','" + dates + "', '" + ReasonAll + "' )";
                                st.executeQuery(query);

                                if (st.executeUpdate(query) == 1) {
                                    String query2 = "Update WORKTR set status ='" + b_status + "' where Start_date='" + dates + "' and Pf_no='" + PFNO + "' and Scan_by='" + PIC + "' and status='" + a_status + "'";
                                    st.executeUpdate(query2);
                                    if(st.executeUpdate(query2)==1){
                                        Toast.makeText(DataModel.this, "Breaktime Recorded", Toast.LENGTH_LONG).show();
                                    }else{
                                        Toast.makeText(DataModel.this, "Update fail", Toast.LENGTH_LONG).show();
                                    }
                                } else {
                                    Toast.makeText(DataModel.this, "Breaktime fail", Toast.LENGTH_LONG).show();
                                }
                            }
                        } catch (Exception ex) {

                        }

                        Log.d("Item " + String.valueOf(i), checkbox.getTag().toString());
                        Toast.makeText(DataModel.this, checkbox.getTag().toString() + " Recorded for break", Toast.LENGTH_SHORT).show();
                    }
                }
//                Toast.makeText(DataModel.this,"Breaktime Recorded", Toast.LENGTH_LONG).show();
            }
        });

The application result to not responding when it comes to the second query. Please help me to view and solve this problems.

来源:https://stackoverflow.com/questions/59940997/failing-to-update-the-table-based-on-checked-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!