基本上目前我的代码正在表中搜索名字或姓氏。完成搜索后,例如 'Peter' ,将发生的情况是将数据放入文本框中。
问题是我希望将数据显示在我的表格上,我已经尝试了很多次但它似乎不起作用,我尝试过使用这行代码。'table_stats' 是表的名称。table_stats.setModel(DbUtils.resultSetToTableModel(Result));
我对这个很陌生,请任何人帮忙,非常感谢谢谢!
private void searchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
String sql = "select * from statistics where first_name =? " ;
String sql2 = "select * from statistics where surname =? " ;
Prepared=conn.prepareStatement(sql);
Prepared=conn.prepareStatement(sql2);
Prepared.setString (1, search.getText());
Result = Prepared.executeQuery();
if(Result.next()){
String add1 = Result.getString("player_id");
player_id.setText(add1);
String add2 = Result.getString("first_name");
first_name.setText(add2);
String add3 = Result.getString("surname");
surname.setText(add3);
String add4 = Result.getString("goal_scored");
goal_scored.setText(add4);
String add5 = Result.getString("assist");
assist.setText(add5);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}