Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a_Zadania.a_Dzien_1.a_Tworzenie_baz_i_tabel;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Main2 {
- //Zapisz w poniższej zmiennej kod zapytania SQL tworzącego pierwszą tabelę
- public static String queryCreateTableProducts = ""+
- "Create table products(" +
- "id int auto_increment,"+
- "name varchar(255),"+
- "price decimal(10,2),"+
- "Primary key(id)"+
- ")";
- //Zapisz w poniższej zmiennej kod zapytania SQL tworzącego drugą tabelę
- public static String queryCreateTableOrders = "Create table `orders` (id int auto_increment primary key, description text);";
- //Zapisz w poniższej zmiennej kod zapytania SQL tworzącego trzecią tabelę
- public static String queryCreateTableClients = "Create table `clients` (`id` int auto_increment primary key, `name` varchar(150), `surname` varchar(150) );";
- // public static String query = "Create database products_ex character set UTF8 collate utf8_unicode_ci;";
- public static void createTable(String query){
- String connUrl = "jdbc:mysql://localhost:3306/products_ex?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false";
- try (Connection conn = DriverManager.getConnection(
- connUrl,
- "root", "coderslab")) {
- Statement st = conn.createStatement();
- st.executeUpdate(query);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- createTable(queryCreateTableClients);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement