I have been busy with a exercise where I need to compare a winning lottery number(which is generated) with existing lottery numbers in a database table.
I manage to loop through all the numbers in the database and subsequently find matches with the winning set of numbers but am struggling to pinpoint in which set of lottery numbers the match was found.
The numbers were placed individually in each database column.
Here I retrieve the values in each row.
ResultSet set = state.executeQuery("SELECT * FROM numberLotto");
while(set.next())
{
String[]row = new String[7];
row[0] = set.getString(1);
row[1] = set.getString(2);
row[2] = set.getString(3);
row[3] = set.getString(4);
row[4] = set.getString(5);
row[5] = set.getString(6);
row[6] = set.getString(7);
entries.add(row);
}
String[][]listOfNumbers = entries.toArray(new String[entries.size()][7]);
I then loop through listOfNumbers and compare all the values with the values of winningNumber.
Object[]winningNumber = lottoDrawString.toArray();
for (int i=0; i < listOfNumbers.length; i++)
{
for (int j=0; j < listOfNumbers[i].length; j++)
{
for(int k = 0; k < winningNumber.length; k++)
{
System.out.println(listOfNumbers[i][j]);
if(listOfNumbers[i][j].equals(winningNumber[k]))
{
System.out.println("There is a match " + listOfNumbers[i][j] + " and " + winningNumber[k]);
}
}
}
}
How can I retrieve the row where the match(es) were found?
kind regards
Why not just do
For that matter, why not just store the lotto numbers as a seven-digit string in the database?