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);
|
}
|
}
|