Advertisement
riking

Check my SQL please

May 25th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1.     public void setupTables() throws SQLException {
  2.         // Let's actually use the database they're asking us to use, mmkay?
  3.         PreparedStatement createDb = connection.prepareStatement("CREATE DATABASE ? IF NOT EXISTS");
  4.         PreparedStatement useDb = connection.prepareStatement("USE ?");
  5.         createDb.setString(0, database);
  6.         useDb.setString(0, database);
  7.         createDb.execute();
  8.         useDb.execute();
  9.         createDb.close();
  10.         useDb.close();
  11.         connection.createStatement().execute("CREATE TABLE players IF NOT EXISTS {" +
  12.                 "name varchar(200) NOT NULL," +
  13.                 "money double NOT NULL," +
  14.                 "}");
  15.         connection.createStatement().execute("CREATE TABLE banks IF NOT EXISTS {" +
  16.                 "bankname varchar(200) NOT NULL," +
  17.                 "owner varchar(200)," +
  18.                 "FOREIGN KEY (owner) REFERENCES players(name)," +
  19.                 "}");
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement