在标题中正确解释问题有点困难,但这正是我正在努力解决的问题;
我正在制作一个程序,希望能够利用两支足球队之前的结果来预测他们之间的结果。结果将存储在 mysql 数据库中。数据库中有21个表,其中1个是过去3年所有比赛的结果,另外20个是每个球队的,包含该球队的各种信息。
我的问题是使用两个 jcombobox 连接到包含所有比赛结果的表,并检索两个特定球队之间的比赛信息。
例如,这是两个 jcombobox 的代码。
private String[] homeTeam = { "Arsenal", "Aston Villa", "Cardiff", "Chelsea", "Crystal Palace", "Everton", "Fulham",
"Hull", "Liverpool", "Manchester City", "Manchester United", "Newcastle", "Norwich", "Southampton", "Stoke", "Sunderland",
"Swansea", "Tottenham", "West Brom", "West Ham"};
private JComboBox box1 = new JComboBox(homeTeam);
private String[] awayTeam = { "Arsenal", "Aston Villa", "Cardiff", "Chelsea", "Crystal Palace", "Everton", "Fulham",
"Hull", "Liverpool", "Manchester City", "Manchester United", "Newcastle", "Norwich", "Southampton", "Stoke", "Sunderland",
"Swansea", "Tottenham", "West Brom", "West Ham" };
private JComboBox box2 = new JComboBox(awayTeam);
所以,假设我想查找结果,如果主队是卡迪夫队,客队是赫尔城,我知道我需要编写什么 sql 查询来做到这一点。但我的问题是,团队的可能组合有很多不同,我最终需要编写数百个查询。
是否可以动态执行此操作,而不是为每种可能的匹配组合编写查询?
谢谢
最佳答案
使用PreparedStatement。您必须编写一条语句,并且可以从 JComboBox 中动态设置值。
关于java - 使用 JComboBox 从 MySQL 数据库动态选择信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21605173/