我必须编写一个应用程序,在其中检索以字符串形式存储在数据库中的乐透号码,并将它们与应用程序本身生成的中奖乐透号码进行比较。
我对此有些困惑。
我首先从数据库中检索6个乐透号码并将其添加到数组列表中。
ArrayList<String> listTwo = new ArrayList<String>();
ResultSet set = state.executeQuery("SELECT * FROM NumbersClients");
while(set.next())
{
String numbers = set.getString(1);
listTwo.add(numbers);
}
我随机生成的数字保存在ArrayList中,然后转换为Integer数组。
Integer[]entries = lottoDraw.toArray(new Integer[lottoDraw.size()]);
关于如何从“ listTwo”中检索每个抽奖并将其与中奖号码(“ entries”)进行比较,从而建立3,4,5个比赛等的任何指示。
谢谢
最佳答案
为什么不将数字分别存储在数据库中。然后生成中奖号码并查询数据库。例如。
SELECT * FROM NumbersClients
WHERE no1 = ? AND no2 = ? AND no3 = ?
etc.
这样您可以避免检索大量不相关的数据