Advertisement
Guest User

Untitled

a guest
May 17th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. package a_Zadania.a_Dzien_1.b_Dodawanie_danych;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. public class Main3 {
  9.  
  10. //zapisz poniżej zapytania dodające rekordy do pierwszej tabeli
  11. public static String table1row1 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa2\", \"jakis adre3\")";
  12. public static String table1row2 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa2\", \"jakis adre3\")";
  13. public static String table1row3 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa3\", \"jakis adres3\")";
  14. public static String table1row4 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa4\", \"jakis adres4\")";
  15. public static String table1row5 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa5\", \"jakis adres5\")";
  16.  
  17. //zapisz postatic niżej zapytania dodające rekordy do drugiej tabeli
  18. public static String table2row1 = "";
  19. public static String table2row2 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa2\", \"jakis opis2\", 9.56)";
  20. public static String table2row3 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa3\", \"jakis opis3\", 9.56)";
  21. public static String table2row4 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa4\", \"jakis opis4\", 9.56)";
  22. public static String table2row5 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa5\", \"jakis opis5\", 9.56)";
  23.  
  24. //zapisz postatic niżej zapytania dodające rekordy do trzeciej tabeli
  25. public static String table3row1 = "INSERT INTO paments(type, date) VALUES(\"jakis typ\", 1030-01-01)";
  26. public static String table3row2 = "INSERT INTO paments(type, date) VALUES(\"jakis typ2\", 1230-01-01)";
  27. public static String table3row3 = "INSERT INTO paments(type, date) VALUES(\"jakis typ3\", 1530-01-01)";
  28. public static String table3row4 = "INSERT INTO paments(type, date) VALUES(\"jakis typ4\", 1630-01-01)";
  29. public static String table3row5 = "INSERT INTO paments(type, date) VALUES(\"jakis typ5\", 1730-01-01)";
  30.  
  31. //zapisz postatic niżej zapytania dodające rekordy do czwartej tabeli
  32. public static String table4row1 = "INSERT INTO paments(quantity, price) VALUES(34, 34.67)";
  33. public static String table4row2 = "INSERT INTO paments(quantity, price) VALUES(56, 38.67)";
  34. public static String table4row3 = "INSERT INTO paments(quantity, price) VALUES(31, 39.67)";
  35. public static String table4row4 = "INSERT INTO paments(quantity, price) VALUES(39, 31.67)";
  36. public static String table4row5 = "INSERT INTO paments(quantity, price) VALUES(314, 13.67)";
  37.  
  38.  
  39.  
  40. public static void main(String[] args) throws SQLException {
  41. String insertOrdersQueryTemplate = table1row1;
  42. try (Connection connection = createConnection();
  43. PreparedStatement statement = connection.prepareStatement(insertOrdersQueryTemplate);) {
  44. // statement.setInt(1, 100);
  45. // statement.setString(2, "StringValue");
  46. System.out.println(statement.executeUpdate());
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51.  
  52. private static Connection createConnection() throws SQLException{
  53. return DriverManager.getConnection("jdbc:mysql://localhost:3306/cinemas_ex", "root", "coderslab");
  54. }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement