두 개의 쿼리를 테이블 모델에 추가하여 테이블에 표시해야합니다. 그것은 축구 (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());
}
}
이제이 코드는 작동하지 않으며 아무 것도 나타나지 않습니다.
도와주세요. 어떤 충고라도 잘 될 것입니다. 당신이 rows.next
을 반복 할 때 행의 수는 == rows2의 수는 다음 문제가 발생할 수 있습니다하지 않는 한
'이제이 코드는 작동하지 않습니다.'- 그게 무슨 뜻입니까? 쿼리에서 반환 된 값을보기 위해 display 문과 같은 기본적인 디버깅 작업을 수행 했습니까? 코드를 간단하게 유지하고 한 번에 하나의 쿼리 만 수행하는 것이 좋습니다. 각 쿼리 후 모델을 업데이트하십시오. – camickr