蓄电池监控管理平台数据库初始化程序
whyclj
2019-01-08 ee24e022c8491d531785d3bfddedad4b39a6eac9
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.database_util;
 
import java.sql.ResultSet;
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class DB_web_site {
    
    
    public static void init(MysqlConnPool pool, boolean recreate) {
        createWeb_siteDB(pool);                                        //´´½¨website Êý¾Ý¿â
        
        createThread_utilTable(pool,recreate);                        //´´½¨Ï߳̿ØÖƱí
    }
    
    public static void createWeb_siteDB(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.WEB_Site);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createThread_utilTable(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.ThreadUtil_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.ThreadUtil_Table + " (" + 
                "  `num` bigint(20) NOT NULL," + 
                "  `thread_id` int(11) NOT NULL COMMENT 'Ïß³Ìid'," + 
                "  `thread_name` varchar(64) NOT NULL DEFAULT 'Ïß³ÌÃû³Æ'," + 
                "  `thread_starttime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00'," + 
                "  `thread_en` int(11) NOT NULL DEFAULT '0' COMMENT 'ÊÇ·ñÆô¶¯±êʶλ 0£ºÄ¬ÈÏ   1£ºÐèÒªÆô¶¯   2:ÔËÐÐÍê³É'," + 
                "  `note` varchar(256) NOT NULL DEFAULT ''," +
                "  UNIQUE KEY `unindex_thread_id` (`thread_id`)," + 
                "  PRIMARY KEY (`num`)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet rs = null;
        try {
            if(true == recreate) {            
                sql.sqlMysqlExecute(sql_str01);
            }
            sql.sqlMysqlExecute(sql_str02);
            rs = sql.sqlMysqlQuery("SELECT * from web_site.tb_thread_util WHERE thread_id = 2019001");
            if(false == rs.next()) {                
                sql.sqlMysqlExecute("INSERT INTO " + Sql_Mysql.ThreadUtil_Table + " VALUES ('1', '2019001', '»ú·¿Ðøº½Ïß³Ì', '2019-01-08 10:44:28', '0', '')");            //Ìí¼Ó»ú·¿Ðøº½Ï̵߳ĿØÖƼǼ
            }
            rs = sql.sqlMysqlQuery("SELECT * from web_site.tb_thread_util WHERE thread_id = 2019002");
            if(false == rs.next()) {                
                sql.sqlMysqlExecute("INSERT INTO " + Sql_Mysql.ThreadUtil_Table + " VALUES ('2', '2019002', 'Âäºóµ¥ÌåÏß³Ì', '2019-01-08 10:44:28', '0', '')");            //Ìí¼Ó»ú·¿Ðøº½Ï̵߳ĿØÖƼǼ
            }
            
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void main(String[] args) {
        MysqlConnPool pool = new MysqlConnPool("123.207.82.239", 3360, 10);
        DB_web_site website = new DB_web_site();
        website.createThread_utilTable(pool, false);
    }
}