Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. package chessleague;
  2.  
  3. import java.sql.*;
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class Chessleague {
  8.  
  9. public static void main(String[] args) throws SQLException, IOException {
  10. try
  11. {
  12. Class.forName ("com.mysql.jdbc.Driver");
  13. try ( //username = root, there is no password
  14. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/chessleague","root","")) {
  15. Statement stmnt = con.createStatement();
  16.  
  17. // Creating Club table
  18.  
  19. stmnt.executeUpdate("CREATE TABLE IF NOT EXISTS Club( "
  20. + "ClubName VARCHAR(30) PRIMARY KEY,"
  21. + "Address VARCHAR(50), "
  22. + "DateFormed DATE)");
  23. System.out.println("Club table created");
  24.  
  25. // Creating Player table
  26.  
  27. stmnt.executeUpdate("CREATE TABLE IF NOT EXISTS Player( "
  28. + "PlayerName VARCHAR(30) PRIMARY KEY,"
  29. + "DateOfBirth DATE,"
  30. + "FIDERating INT,"
  31. + "FIDETitle VARCHAR(30), "
  32. + "ClubName VARCHAR(30), "
  33. + "FOREIGN KEY (ClubName) REFERENCES Club(ClubName))");
  34. System.out.println("Player table created");
  35.  
  36. // Creating Match table
  37.  
  38. stmnt.executeUpdate("CREATE TABLE IF NOT EXISTS MatchTable( "
  39. + "MatchID VARCHAR(10) PRIMARY KEY,"
  40. + "MatchTime DATE,"
  41. + "Venue VARCHAR(50),"
  42. + "Score VARCHAR(10),"
  43. + "WinningClub VARCHAR(30),"
  44. + "LosingClub VARCHAR(30))");
  45. System.out.println("MatchTable created");
  46.  
  47. // Creating Game table
  48.  
  49. stmnt.executeUpdate("CREATE TABLE IF NOT EXISTS Game( "
  50. + "GameID VARCHAR(10) PRIMARY KEY,"
  51. + "DatePlayed DATE,"
  52. + "BoardNum INT,"
  53. + "Score VARCHAR(10),"
  54. + "MatchID VARCHAR(10),"
  55. + "FOREIGN KEY (MatchID) REFERENCES MatchTable (MatchID),"
  56. + "WhitePlayer VARCHAR(20),"
  57. + "BlackPlayer VARCHAR(20))");
  58. System.out.println("Game table created");
  59.  
  60. con.commit();
  61. con.close();
  62.  
  63. // ResultSet rs=stmnt.executeQuery("select * from emp");
  64. // while(rs.next())
  65. // System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
  66. }
  67. }
  68. catch (ClassNotFoundException | SQLException e){ System.out.println(e);
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement