Code Collection

public void Updatetb222() {

DefaultTableModel md = new DefaultTableModel();

tb2.setModel(md);

tb2.setRowHeight(20); //Row Height

JTableHeader th = tb2.getTableHeader();

th.setBackground(Color.YELLOW);

th.setForeground(Color.BLUE);

th.setFont(new Font("Phetsarath OT", Font.BOLD, 14));

// b3.setBackground(Color.PINK);

// b3.setGridColor(Color.RED);

//TableColumn col1 = b3.getColumnModel().getColumn(0);

// col1.setPreferredWidth(20);

String sql = "select No as 'ເລກທີ', Name as 'ຊື່', Surname as 'ນາມສະກຸນ', Gender as 'ເພດ', Book as 'ສໍາມະໂນ', House as 'ເລກເຮືອນ', Unit as 'ໜ່ວຍ', Tell as 'ເບີໂທ' from People order by No ASC";

try {

st = c.prepareStatement(sql);

rs = st.executeQuery();

tb2.setModel(DbUtils.resultSetToTableModel(rs));

} catch (Exception e) {}

finally { try { rs.close(); st.close();} catch (Exception e) { } }

}

public void Cal1(){

int sum = 0;

for(int i=0; i<tb2.getRowCount();i++){

sum = sum + 1;

}

l1.setText(String.valueOf(sum));

}

/*

float sum = 0;


//int sum1 = 0;


for(int i=0; i<b3.getRowCount();i++){


sum = sum + Float.parseFloat(b3.getValueAt(i, 3).toString());


//sum1 = sum1 + Integer.parseInt(b3.getValueAt(i, 2).toString());


}

r3.setText(String.format("%.2f", sum));

float R = Float.parseFloat(r1.getText());

R = sum/R;

r4.setText(String.format("%.2f", R));

float R1 = Float.parseFloat(r2.getText());

R1 = sum/R1;

r5.setText(String.format("%.2f", R1));

T.append("\n\n\t\t\t\t\tລວມ\tກີບ "+r3.getText()+"\n\t\t\t\t\t\tບາດ "+r4.getText()+"\n\t\t\t\t\t\tໂດລາ "+r5.getText());

*/

public void Wom() {

String AA = "ຊາຍ";

String sql = "select * from People where Gender = ? ";

try {

st = c.prepareStatement(sql);

st.setString(1, AA);

rs = st.executeQuery();

tb3.setModel(DbUtils.resultSetToTableModel(rs));

int sum = 0;

for(int i=0; i<tb3.getRowCount();i++){

sum = sum + 1;

}

l3.setText(String.valueOf(sum));

int male = Integer.parseInt(l1.getText());

male = male - sum;

l2.setText(String.valueOf(male));

} catch (Exception e) {}

finally { try { rs.close(); st.close();} catch (Exception e) { } }

}

public void Unit() {

String sql = "select distinct(unit) from People";

try {

st = c.prepareStatement(sql);

rs = st.executeQuery();

tb4.setModel(DbUtils.resultSetToTableModel(rs));

int sum = 0;

for(int i=0; i<tb4.getRowCount();i++){

sum = sum + 1;

}

l4.setText(String.valueOf(sum));

} catch (Exception e) {}

finally { try { rs.close(); st.close();} catch (Exception e) { } }

}

public void House(){

String sql = "select distinct(House) from People";

try {

st = c.prepareStatement(sql);

rs = st.executeQuery();

tb5.setModel(DbUtils.resultSetToTableModel(rs));

int sum = 0;

for(int i=0; i<tb5.getRowCount();i++){

sum = sum + 1;

}

l5.setText(String.valueOf(sum));

} catch (Exception e) {}

finally { try { rs.close(); st.close();} catch (Exception e) { } }

}

public void Book(){

String sql = "select distinct(Book) from People";

try {

st = c.prepareStatement(sql);

rs = st.executeQuery();

tb6.setModel(DbUtils.resultSetToTableModel(rs));

int sum = 0;

for(int i=0; i<tb6.getRowCount();i++){

sum = sum + 1;

}

l6.setText(String.valueOf(sum));

} catch (Exception e) {}

finally { try { rs.close(); st.close();} catch (Exception e) { } }

}