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.