我是java的新手。目前正试图制作一个用mysql数据操作的程序。我在mysql中有几个表,我需要将数据添加到2个mysql表中的单个jtable行。现在我在不同的行中获取数据。在我的代码下面有一个表。有任何建议如何更改吗?
public void fill_rs_table_test(){
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(new String[] {"rs_name","rs_number","firm_id"});
try{
String sql = "select * from inf_rs";
theView.pst = theView.conn.prepareStatement(sql);
theView.rs = theView.pst.executeQuery();
while(theView.rs.next()){
String rs_name = theView.rs.getString ("rs_name");
String rs_number = theView.rs.getString ("rs_number");
String firm_id = theView.rs.getString ("firm_id");
model.addRow(new Object[] {rs_name, rs_number,firm_id});
}
}
catch (Exception e){
}
this.theView.rs_table.setModel(model);
for (int i = 0, x = 0; i < theView.rs_table.getColumnModel().getColumnCount(); i++)
this.theView.rs_table.getColumnModel().getColumn(i).setCellEditor(new javax.swing.table.TableCellEditor(){
@Override
public boolean isCellEditable(java.util.EventObject anEvent) {
return false;
}
});