Okay, so this is what I have so far and it works. However, I'm not able to specify to which ? (or parameter) the int 1 or 0 (boolean converted to int) is set (through setInt()). I tried using the getName() to see the component variable name but it returns null when I print it.
How can I assign a checkbox's value as parameter to my PreparedStatement if I'm not able to specify correctly on which textbox the value of 1 or 0 is from?
ps.setInt(1,valueOfUnknownCheckbox);//need to put the correct checkbox as 2nd argument.I saw some information about using
Java Reflectionwhich I'm totally unfamiliar with. Is there any way without usingJava Reflection?
Some of the checkbox values are not going to the correct database table's column.
I hope you can help with me guys. I wanted to be able to use List to collect components from containers to lessen the lines of codes.
Here's my code.
private void saveAdminPermissions(){
List<Component> adminPermissionsChbxs = fm.getComponentsAsList(administrationPermissionsCheckBoxPanel);
Boolean bool = null;
String updateSQL =
"UPDATE allusers_admin_permissions SET CURC_BTN=?, DISCOUNTS_BTN=?, SECTIONS_BTN=?,"
+ " USERS_BTN=?, SCHEDULING_BTN=?, YRLEVELS_BTN=?, ACCTG_BTN=? WHERE USERID=? ";
try(Connection con = DBUtil.getConnection(DBType.MYSQL);
PreparedStatement ps = con.prepareStatement(updateSQL);)
{
int x=1;
for(Component c : adminPermissionsChbxs){
if(c instanceof JCheckBox){
bool = ( (JCheckBox)c ).isSelected();
JOptionPane.showMessageDialog(null,"Name: "+ ((JCheckBox)c).getName() );
JOptionPane.showMessageDialog(null,bool);
} //--end of if
int boolToInt = (bool)?1:0 ;
ps.setInt(x, boolToInt);
x++;
}//--end of forloop
ps.setInt(8, um.getIdOfSelected(usersList));
ps.executeUpdate(); JOptionPane.showMessageDialog(null,"Update successful");
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"Error@saveAdminPermissions\n"+ e.getMessage());
}
}//--end of method
Thanks.