title: Creating a database and tables in MySQL using a JDBC application
body: <p>I've created a program in Java for a school project. I created the database and tables using MySQL Workbench, but now I need my program to work on other computers and therefore I need it to check if the database and tables exist, and if not create them on its own.</p>
  
  <p>This is the relevant code in my driver class as it stands:</p>
  
  <pre><code>private static Connection conn;
  
  static
  {
      try
      {
          Class.forName("com.mysql.jdbc.Driver");
      }
      catch (ClassNotFoundException exc)
      {
          javax.swing.JOptionPane.showMessageDialog(null, "Oops! Something seems to have gone wrong!\n\n" + exc, "Error", JOptionPane.ERROR_MESSAGE);
      }
  }
  
  public static Connection getMySQLConnection() throws SQLException
  {
      conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tournament_manager", "studentCouncil", "****");
      return conn;
  }
  </code></pre>
  
  <p>As above, the database I would like to create, if it does not exist, is to be called "tournament_manager". The tables to be created with the database are as follows:</p>
  
  <p><strong>Table 1 Name: password</strong></p>
  
  <p>Column 1: passwordID
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>Column 2: password
  <em>Type:</em> varchar(20)
  <em>Nullable:</em> YES
  <em>Character Set:</em> latin1</p>
  
  <p><strong>Table 2 Name: tournaments</strong></p>
  
  <p>Column 1: tournamentID
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO
  <em>Extra:</em> auto_increment</p>
  
  <p>Column 2: tournamentName
  <em>Type:</em> varchar(20)
  <em>Nullable:</em> NO
  <em>Character Set:</em> latin1</p>
  
  <p>Column 3: date
  <em>Type:</em> date
  <em>Nullable:</em> NO</p>
  
  <p>Column 4: startTime
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>Column 5: matchDuration
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>Column 6: breakDuration
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>Column 7: numTeams
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>Column 8: numVenues
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p><strong>Table 3 Name: teams</strong></p>
  
  <p>Column 1: teamID
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO
  <em>Extra:</em> auto_increment</p>
  
  <p>Column 2: teamName
  <em>Type:</em> varchar(20)
  <em>Nullable:</em> NO
  <em>Character Set:</em> latin1</p>
  
  <p>Column 3: points
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>Column 4: tournaments_tournamentID
  <em>Type:</em> int(11)
  <em>Nullable:</em> NO</p>
  
  <p>I am new to stack overflow, so I may have not included all the relevant information or included irrelevant information. In the case that I haven't included relevant details, please ask.</p>
  
  <p>Thank you in advance for the support!</p>