【发布时间】:2017-06-20 19:47:48
【问题描述】:
好的,我做了一个新的更新 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) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 使用逻辑一致的形式缩进代码行和块。缩进是为了让代码流更容易理解! 3)IDE与问题无关。不要在标题中提及,或者添加标签。