抱歉代码很大。问题是rs.next似乎根本不执行,因为
System.out.println("//////////////////////////////////");
不会打印任何内容。
String Temp2;
Temp2 = ""; //initialise variable
System.out.println("*************************************************");
try
{
String filename = "Database.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database += filename.trim() + ";DriverID=22;READONLY=false";
conn = DriverManager.getConnection(database, "", "");
for(int id = 1; id < 16; id++)//will repeat 15 times (for each player)
{
for(int x = 1; x < 18; x++)//will repeat 18 times (once for each team fixture)
{
Statement sta2 = conn.createStatement();
ResultSet rs2 = sta2.executeQuery("SELECT * FROM tblPlayers WHERE PlayerID = "+ PlayerID +" AND FixtureNumber = "+ x);
while (rs2.next())
{
Temp2 = rs2.getString("PlayerName");
System.out.println("//////////////////////////////////");
System.out.println(Temp2 + ":Temp2");
Total = Total + rs2.getInt("Goals");//calculating total
System.out.println(Total + ":Total");
}
}
if (Total.equals(TotalsRev[0])){
PlayerName[0] = Temp2;
}else if (Total.equals(TotalsRev[1])){
PlayerName[1] = Temp2;
}else if (Total.equals(TotalsRev[2])){
PlayerName[2] = Temp2;
}else if (Total.equals(TotalsRev[3])){
PlayerName[3] = Temp2;
}else if (Total.equals(TotalsRev[4])){
PlayerName[4] = Temp2;
}
}
PlayerID = 0;//reset variable
for(int x = 0; x < 5; x++){
System.out.println(PlayerName[x]);
}
System.out.println("*********************************************");
System.out.println(TotalsRev[0]);
System.out.println(TotalsRev[1]);
System.out.println(TotalsRev[2]);
System.out.println(TotalsRev[3]);
System.out.println(TotalsRev[4]);
jLabel10.setText(PlayerName[0] + "");
jLabel11.setText(PlayerName[1] + "");
jLabel12.setText(PlayerName[2] + "");
jLabel13.setText(PlayerName[3] + "");
jLabel14.setText(PlayerName[4] + "");
}
catch (Exception e)
{
System.out.println("Exception displayTotalAttributes:" + e);
}
finally //close down connection to prevent "too many tables open" error
{
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {}
}
}
控制台中的输出是:
“的 ********************************************* < /强>“
// System.out.println("//////////////////////////////////");
应该在这里执行
Omicron //团队名称
null //这些也应该是团队名称
null
null
null
“的 ***************************************** ”
15个
14个
13个
12个
11"