Guest User

Untitled

a guest
Apr 26th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package a_Zadania.a_Dzien_2.c_Relacje_1_1;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class Main3 {
  10. public static String queryCreateTable ="CREATE TABLE Payments(\n" +
  11. " id int AUTO_INCREMENT,\n" +
  12. " tickets_id int NOT NULL,\n" +
  13. " type varchar(255),\n" +
  14. " date DATE,\n" +
  15. " PRIMARY KEY(id),\n" +
  16. " FOREIGN KEY(tickets_id)\n" +
  17. " REFERENCES Tickets(id)\n" +
  18. " ON DELETE CASCADE\n" +
  19. " );";
  20. public static void main(String[] args) {
  21.  
  22. try (Connection conn = DriverManager
  23. .getConnection("jdbc:mysql://localhost:3306/cinemas?useSSL=false",
  24. "root", "coderslab")) {
  25. Statement stmt = conn.createStatement();
  26. stmt.executeUpdate(queryCreateTable);
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30.  
  31. }
  32. }
Add Comment
Please, Sign In to add comment