基本上當前我的代碼正在搜索表中的第一個姓或名。一旦完成搜索,例如'彼得',會發生什麼是數據將被放置到文本框中。在搜索後在Jtable上顯示數據
問題是我想要數據顯示到我的表上,我已經嘗試了很多次,但似乎沒有工作,我試過使用這一行代碼。 'table_stats'是表格的名字。 table_stats.setModel(DbUtils.resultSetToTableModel(結果));
我對此很新,任何人都可以請幫忙,非常感謝你!
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);
}
}
+1爲一個很好的答案。 – 2013-04-25 13:32:41