-
October 26th, 1999, 06:40 AM
#1
how to add objects to the defaulttable model ?
how do i add the rows to the jtables.
using my method, it is not a good way to add it.
as i need to check j==0 , j==1 ...etc.
//import java.util.Vector;
import java.sql.*;
import OraDB;
import javax.swing.*;
import javax.swing.table.*;
public class TTab extends JPanel {
String strDateFrom = "19990701";
String strDateTo = "19990920";
String str3= "select em.state_name, count(*) from Employer_Master em, Foreign_Worker_Master fwm where fwm.employer_code = em.employer_code" ;
// "(certify_date > TO_DATE('" + strDateFrom + "','YYYYMMDD') and certify_date < // TO_DATE('"+strDateTo+"','YYYYMMDD') ) ";
String str2 = "select count(d.worker_code) from foreign_worker_master fm, " +
" fw_certified_details d where d.fit_ind = 'N' ";
TTab() {
OraDB db = new OraDB();
Object colHeaders[] = {"State Name", "Total"};
DefaultTableModel tabModel = new DefaultTableModel(colHeaders, 0);
try {
ResultSet rs = db.query(str3);
int j = 0;
while (rs.next()) {
/* how do i add the rows returned to be rows in the jtable
*/
if (j == 0) {
Object iname[] = { rs.getString(1), rs.getString(2) };
tabModel.addRow(iname);
}
if (j == 1) {
Object iname1[] = { rs.getString(1), rs.getString(2)};
tabModel.addRow(iname1);
}
if (j == 2) {
Object iname2[] = { rs.getString(1), rs.getString(2)};
tabModel.addRow(iname2);
}
if (j == 3) {
Object iname3[] = { rs.getString(1), rs.getString(2)};
tabModel.addRow(iname3);
}
if (j == 4) {
Object iname4[] = { rs.getString(1), rs.getString(2)};
tabModel.addRow(iname4);
}
if (j == 5) {
Object iname4[] = { rs.getString(1), rs.getString(2)};
tabModel.addRow(iname4);
}
j++;
} // end while
} catch( Exception e ) {
System.out.println(e.getMessage());
e.printStackTrace();
}
JTable tab = new JTable(tabModel);
add("Center", new JScrollPane(tab));
} // end TTab()
/* ====== main ========= */
public static void main( String[] str ) {
JFrame frame = new JFrame();
TTab tab = new TTab();
frame.getContentPane().add(tab);
frame.setSize( 300,300 );
frame.setVisible( true );
}
} // end of TTab
http://members.xoom.com/lookads
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|