Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a_Zadania.a_Dzien_1.b_Dodawanie_danych;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class Main3 {
- //zapisz poniżej zapytania dodające rekordy do pierwszej tabeli
- public static String table1row1 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa2\", \"jakis adre3\")";
- public static String table1row2 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa2\", \"jakis adre3\")";
- public static String table1row3 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa3\", \"jakis adres3\")";
- public static String table1row4 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa4\", \"jakis adres4\")";
- public static String table1row5 = "INSERT INTO cinemas(name, adress) VALUES(\"jakas nazwa5\", \"jakis adres5\")";
- //zapisz postatic niżej zapytania dodające rekordy do drugiej tabeli
- public static String table2row1 = "";
- public static String table2row2 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa2\", \"jakis opis2\", 9.56)";
- public static String table2row3 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa3\", \"jakis opis3\", 9.56)";
- public static String table2row4 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa4\", \"jakis opis4\", 9.56)";
- public static String table2row5 = "INSERT INTO movies(name, description, rating) VALUES(\"jakas nazwa5\", \"jakis opis5\", 9.56)";
- //zapisz postatic niżej zapytania dodające rekordy do trzeciej tabeli
- public static String table3row1 = "INSERT INTO paments(type, date) VALUES(\"jakis typ\", 1030-01-01)";
- public static String table3row2 = "INSERT INTO paments(type, date) VALUES(\"jakis typ2\", 1230-01-01)";
- public static String table3row3 = "INSERT INTO paments(type, date) VALUES(\"jakis typ3\", 1530-01-01)";
- public static String table3row4 = "INSERT INTO paments(type, date) VALUES(\"jakis typ4\", 1630-01-01)";
- public static String table3row5 = "INSERT INTO paments(type, date) VALUES(\"jakis typ5\", 1730-01-01)";
- //zapisz postatic niżej zapytania dodające rekordy do czwartej tabeli
- public static String table4row1 = "INSERT INTO paments(quantity, price) VALUES(34, 34.67)";
- public static String table4row2 = "INSERT INTO paments(quantity, price) VALUES(56, 38.67)";
- public static String table4row3 = "INSERT INTO paments(quantity, price) VALUES(31, 39.67)";
- public static String table4row4 = "INSERT INTO paments(quantity, price) VALUES(39, 31.67)";
- public static String table4row5 = "INSERT INTO paments(quantity, price) VALUES(314, 13.67)";
- public static void main(String[] args) throws SQLException {
- String insertOrdersQueryTemplate = table1row1;
- try (Connection connection = createConnection();
- PreparedStatement statement = connection.prepareStatement(insertOrdersQueryTemplate);) {
- // statement.setInt(1, 100);
- // statement.setString(2, "StringValue");
- System.out.println(statement.executeUpdate());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private static Connection createConnection() throws SQLException{
- return DriverManager.getConnection("jdbc:mysql://localhost:3306/cinemas_ex", "root", "coderslab");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement