티스토리 뷰

Language/JAVA

Java create table

KyeongRok Kim 2018. 7. 27. 14:17

users 테이블 생성

public void createTable() throws SQLException, ClassNotFoundException {

    Connection c = connectionMaker.getConnection();
    Statement stmt = c.createStatement();
    String sql = "CREATE TABLE IF NOT EXISTS users (\n"
            + "    id VARCHAR(45) NOT NULL,\n"
            + "    name VARCHAR(45) NOT NULL,\n"
            + "    password VARCHAR(45)\n"
            + ");";
    stmt.execute(sql);

}

 

JdbcTemplate을 이용해 Table생성하기

public int createTable() {
    // table이 있는지 먼저 check
    return this.jdbcTemplate.update(String.format("create table if not exists " +
            "customer_service_record(id bigint, car_model_id int, cs_start_date timestamp," +
            " contents text, PRIMARY KEY (id))"));
}

 

부동산 정보 테이블

CREATE TABLE `estate` (

  `id` bigint(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '아이디',

  `city` varchar(255) DEFAULT NULL,

  `gu` varchar(255) DEFAULT NULL,

  `dong` varchar(255) DEFAULT NULL,

  `deposit` int(11) DEFAULT NULL COMMENT '보증금',

  `monthly_rent` int(11) DEFAULT NULL,

  `type` int(11) DEFAULT NULL,

  `floor` int(11) DEFAULT NULL,

  `supply_area` int(11) DEFAULT NULL,

  `exclusive_area` double DEFAULT NULL,

  `price` double DEFAULT NULL,

  `average_price` double DEFAULT NULL,

  `price_score` double DEFAULT NULL,

  `average_maintenance_cost` double DEFAULT NULL,

  `average_maintenance_properties` double DEFAULT NULL,

  `agency` varchar(255) DEFAULT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함