Advertisement
Guest User

Untitled

a guest
May 13th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. SELECT MatchTeam.FootballMatchID, MatchTeam.TeamID, MatchTeam.GameType, MatchProtocol.MatchTeamID, MatchProtocol.GoalNumber, MatchProtocol.YellowCardNumber, MatchProtocol.RedCardNumber
  2. FROM MatchTeam LEFT JOIN MatchProtocol ON MatchTeam.ID = MatchProtocol.MatchTeamID
  3. WHERE (((MatchTeam.GameType)="Away"));
  4.  
  5. SELECT MatchTeam.FootballMatchID, MatchTeam.TeamID, MatchTeam.GameType, MatchProtocol.MatchTeamID, MatchProtocol.GoalNumber, MatchProtocol.YellowCardNumber, MatchProtocol.RedCardNumber
  6. FROM MatchTeam LEFT JOIN MatchProtocol ON MatchTeam.ID = MatchProtocol.MatchTeamID
  7. WHERE (((MatchTeam.GameType)="Home"));
  8.  
  9. SELECT qryHomeMatches.FootballMatchID, qryHomeMatches.TeamID AS HomeTeamID, qryAwayMatches.TeamID AS AwayTeamID, qryHomeMatches.GoalNumber AS HomeTeamGoals, qryAwayMatches.GoalNumber AS AwayTeamGoals, [HomeTeamGoals]>[AwayTeamGoals] AS HomeTeamWin, [HomeTeamGoals]=[AwayTeamGoals] AS NoWin, [HomeTeamGoals]<[AwayTeamGoals] AS AwayTeamWin
  10. FROM qryHomeMatches INNER JOIN qryAwayMatches ON qryHomeMatches.FootballMatchID = qryAwayMatches.FootballMatchID;
  11.  
  12. btnqryAwayMatches.addActionListener(new ActionListener() {
  13. public void actionPerformed(ActionEvent e) {
  14. Connection con = null;
  15. Statement st = null;
  16. ResultSet rs = null;
  17. String s;
  18. JFrame frame;
  19. String url = "jdbc:hsqldb:file:db_data/myFootballDB;ifexists=true;shutdown=true";
  20. String username = "SA";
  21. String password = "";
  22.  
  23. try {
  24. con = DriverManager.getConnection(url, username, password);
  25. st = con.createStatement();
  26. s = "SELECT MATCHTEAM.FOOTBALLMATCHID, MATCHTEAM.TEAMID, MATCHTEAM.GAMETYPE, "
  27. + "MATCHPROTOCOL.MATCHTEAMID, MATCHPROTOCOL.GOALNUMBER, "
  28. + "MATCHPROTOCOL.YELLOWCARDNUMBER, "
  29. + "MATCHPROTOCOL.REDCARDNUMBER "
  30. + "FROM MATCHTEAM LEFT JOIN MATCHPROTOCOL ON MATCHTEAM.ID = MATCHPROTOCOL.MATCHTEAMID "
  31. + "WHERE (((MATCHTEAM.GAMETYPE)='Away'));";
  32. rs = st.executeQuery(s);
  33. ResultSetMetaData rsmt = rs.getMetaData();
  34. int c = rsmt.getColumnCount();
  35. Vector<String> column = new Vector<String>(c);
  36. for (int i = 1; i <= c; i++) {
  37. column.add(rsmt.getColumnName(i));
  38. }
  39. Vector<Vector<String>> data = new Vector<Vector<String>>();
  40. Vector<String> row = new Vector<String>();
  41. while (rs.next()) {
  42. row = new Vector<String>(c);
  43. for(int i = 1; i <= c; i++) {
  44. row.add(rs.getString(i));
  45. }
  46. data.add(row);
  47. }
  48.  
  49. frame = new JFrame();
  50. frame.setTitle("Away Match Results");
  51. frame.setSize(700,420);
  52. frame.setLocationByPlatform(true);
  53. frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  54. JPanel panel = new JPanel();
  55. JTable table = new JTable(data, column);
  56. JScrollPane jsp = new JScrollPane(table);
  57. panel.setLayout(new BorderLayout());
  58. panel.add(jsp, BorderLayout.CENTER);
  59. frame.setContentPane(panel);
  60. frame.setVisible(true);
  61.  
  62. } catch(Exception exc) {
  63. exc.printStackTrace();
  64. JOptionPane.showMessageDialog(null, "Error");
  65. } finally {
  66. try {
  67. st.close();
  68. rs.close();
  69. con.close();
  70. } catch(Exception exception) {
  71. JOptionPane.showMessageDialog(null, "Error close");
  72. }
  73. }
  74. }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement