我正在使用MS Access数据库,我将匹配的Man存储为是/否复选框。下面代码的目的是检查是否勾选了复选框。如果勾选,则将一个添加到TotalMoM。
问题是TotalMoM始终为1(即使勾选了多个复选框)或0(如果勾选了零复选框)。
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 x = 1; x < 18; x++)//will repeat 18 times (once for each team fixture)
{
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery("SELECT * FROM tblPlayers WHERE PlayerID = "+ PlayerID +" AND FixtureNumber = "+ x);
while (rs.next())
{
MoM = false; //initialising variable
TotalMoM = 0;
MoM = rs.getBoolean("MoM");
if (MoM){ //if Man of the Match checkbox is ticked
TotalMoM = TotalMoM + 1; //calculating total
}
jLabel12.setText(String.valueOf(TotalMoM));
}
}
}
catch (Exception e)
{
System.out.println("Exception e:" + e);
}
答案 0 :(得分:0)
试试这个..
MoM = false; //initialising variable
TotalMoM = 0;
while (rs.next())
{
MoM = rs.getBoolean("MoM");
if (MoM){ //if Man of the Match checkbox is ticked
TotalMoM = TotalMoM + 1; //calculating total
}
jLabel12.setText(String.valueOf(TotalMoM));