package io.khasang.webstore.model;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

public class CreateDataTable {
    public static String sqlCheck;

    public void sqlInsert(){
        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
        dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
        dataSource.setUsername("root");
        dataSource.setUrl("jdbc:mysql://localhost/webstore");
        dataSource.setPassword("root");
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        System.out.println("try to update db...");
        try{
            System.out.println("creating tables");
                jdbcTemplate.execute("DROP TABLE IF EXISTS products");
                jdbcTemplate.execute("create table products(ID INT NOT NULL, "
                + " pName MEDIUMTEXT NOT NULL, description LONGTEXT)");
            jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(1, 'apple', 'red')");
            jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(2, 'milk', 'natural')");
            jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(3, 'bred', 'null')");
                + " pName MEDIUMTEXT NOT NULL, descr LONGTEXT)");
            jdbcTemplate.update("INSERT INTO products(ID, pName, descr) VALUES(1, 'apple', 'red')");
            jdbcTemplate.update("INSERT INTO products(ID, pName, descr) VALUES(2, 'milk', 'natural')");
            jdbcTemplate.update("INSERT INTO products(ID, pName, descr) VALUES(3, 'bred', 'null')");
            sqlCheck = "db updated";
        }  catch (Exception e){
            sqlCheck = "have error: "+e;
            System.out.println(sqlCheck);
        }
    }

    public String sqlInsertCheck(){
        CreateDataTable sql = new CreateDataTable();
        sql.sqlInsert();
        return sqlCheck;
    }
}

@@ -242,18 +242,19 @@
 Insert()
+ 
 %7B%0A
-
         
@@ -653,16 +653,17 @@
      try
+ 
 %7B%0A      
@@ -711,36 +711,32 @@
 %22);%0A            
-    
 jdbcTemplate.exe
@@ -778,36 +778,32 @@
 %22);%0A            
-   
- 
 jdbcTemplate.exe
@@ -857,32 +857,36 @@
                 
+    
 + %22 pName MEDIUM
@@ -929,398 +929,8 @@
 %22);%0A
-            jdbcTemplate.update(%22INSERT INTO products(ID, pName, description) VALUES(1, 'apple', 'red')%22);%0A            jdbcTemplate.update(%22INSERT INTO products(ID, pName, description) VALUES(2, 'milk', 'natural')%22);%0A            jdbcTemplate.update(%22INSERT INTO products(ID, pName, description) VALUES(3, 'bred', 'null')%22);%0A                + %22 pName MEDIUMTEXT NOT NULL, descr LONGTEXT)%22);%0A
     
@@ -1277,17 +1277,16 @@
        %7D
- 
  catch (
@@ -1297,16 +1297,17 @@
 ption e)
+ 
 %7B%0A      
@@ -1337,17 +1337,19 @@
 error: %22
-+
+ + 
 e;%0A     
@@ -1402,16 +1402,16 @@
 %0A    %7D%0A%0A
-
     publ
@@ -1436,16 +1436,17 @@
 tCheck()
+ 
 %7B%0A      

fix create sql query