好吧,伙计们,我更新了一个新的Jtable代码,但是它不工作,你们能告诉我为什么吗?
代码如下:
private void update(){
DefaultTableModel modelo = new DefaultTableModel();
try{
Connection lig;
lig = DriverManager.getConnection("jdbc:mysql://localhost/bdteste","root","");
PreparedStatement inst;
inst = (PreparedStatement) lig.createStatement();
ResultSet res;
res = inst.executeQuery("SELECT * FROM pessoa");
while(res.next()){
int id = res.getInt("ID");
String descriçao = res.getString("Descriçao");
double montante = res.getDouble("Montante");
String categoria = res.getString("Categoria_Extrato");
model.addRow(new Object[]{id, descriçao, montante, categoria});
}
res.close();
inst.close();
lig.close();
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null, "Erro na base de dados!");
}
recdadostbl.setModel(modelo);
}这就是发生的事情:Me inserting the dataError1
发布于 2017-06-22 19:22:10
我想我找到了我的问题的解决方案。当我进入我的表格面板时,我删除了所有的表格model.setRowCount(0);,然后我用这个方法重新插入了所有的新旧数据。
public void updatetbl()
{
try {
Connection lig;
lig = DriverManager.getConnection("jdbc:mysql://localhost/financas","root","");
Statement inst;
inst = lig.createStatement();
ResultSet res = inst.executeQuery("SELECT * FROM extrato");
while(res.next()){
int id = res.getInt("ID");
String descriçao = res.getString("Descriçao");
double montante = res.getDouble("Montante");
String categoria = res.getString("Categoria_Extrato");
model.addRow(new Object[]{id, descriçao, montante, categoria});
}
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"Base de Dados Indisponivel"+ex );
}
}https://stackoverflow.com/questions/44661820
复制相似问题