private void Update_table(){
try {
String sql= "select Firstname, Lastname,ID_number from regmembers";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
jTable_regMembers.setModel(DbUtils.resultSetToTableModel(rs));
jTable_regMembers.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTable_regMembers.getTableHeader().setReorderingAllowed(false);
jTable_regMembers.getTableHeader().setResizingAllowed(false);
} catch(Exception e){
JOptionPane.showMessageDialog(null, e+"");
}
}
如何显示我的数据库注册成员的数据并将其放入jtextfield,新手问题?
答案 0 :(得分:1)
迭代结果集对象并设置获得的值
ResultSet resultSet = ps.executeQuery();
if (resultSet.next()) {
do {
// perform your logic
yourTextfield.setText(rs.getString("yourColumnName"));
} while(resultSet.next());
答案 1 :(得分:0)
您应该能够执行简单查询并使用结果集中的值来设置文本字段。
String sql = "Select count(*) from regmembers";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
textfield.setText(rs.getInt(1));
希望这可以按你想要的方式工作