1
好吧,我做了一个新的更新Jtable代码,但它不工作,你能帮我理解为什么吗?当我更新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
1)为了更好地帮助更快,发布[MCVE]或[短,自成一格,正确的例子](http://www.sscce.org/)。 2)使用合乎逻辑的一致形式缩进代码行和块。缩进旨在使代码的流程更易于遵循! 3)IDE与问题无关。不要在标题中提及它,或者添加标签。 –