我必须向表模型添加两个查询,以便它显示在表上。这是一个对足球进行预测的程序(准确地说是 EPL),我需要显示球队在主场和客场比赛时的所有结果。第一个查询是获取他们在家打球的所有比赛,第二个查询是他们何时打客场。这是代码:
public void showResultsTotalTeam(){
deleteAllRows(dTableModel); // deleta all rows in the table
try {
conn = DriverManager.getConnection(connection.conn_url, connection.conn_user, connection.conn_pass);// connect to database server
Statement sqlState = conn.createStatement();// create statement for sql
String selectStuff = "SELECT games_team1, games_team2, games_winner, games_draw, games_team1_score, games_team2_score, games_month, games_day FROM games WHERE games_team1 = '" + cbxTeam1.getSelectedItem() + "'";// ststement for MySQL
rows = sqlState.executeQuery(selectStuff); // execute statement
String selectStuff2 = "SELECT games_team1, games_team2, games_winner, games_draw, games_team1_score, games_team2_score, games_month, games_day FROM games WHERE games_team2 = '" + cbxTeam1.getSelectedItem() + "'";// ststement for MySQL
rows2 = sqlState.executeQuery(selectStuff); // execute statement
Object[] tempRow;// create object array to store queried results
Object[] tempRow2;
while(rows.next()){ // while there are still values to be seen to
tempRow = new Object[]{rows.getString(1), rows.getString(2), rows.getString(3), rows.getString(4), rows.getString(5), rows.getString(6), rows.getString(7), rows.getString(8)};// add data to array
tempRow2 = new Object[]{rows2.getString(1), rows2.getString(2), rows2.getString(3), rows2.getString(4), rows2.getString(5), rows2.getString(6), rows2.getString(7), rows2.getString(8)};
dTableModel.addRow(tempRow); // add array to table model
dTableModel.addRow(tempRow2);
}
} catch (SQLException ex) {
// TODO Auto-generated catch block
System.out.println(ex.getMessage());
}
}
现在这段代码不起作用,什么也没有出现。
请帮忙?任何建议都会很棒。