java 创建 数据库 表

package com.baishiji.action.task;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.baishiji.uploadrecord.db.Db;

public class CreadSql {
	/*
	 * 分析 : 1.连接上数据库 , 2.创建 子表
	 */
	public boolean creadSo(String name) {
		StringBuilder sb = new StringBuilder();

		sb.append("create table  o_task_run_"+name+" ( ");
		sb.append("[id] [int] IDENTITY(1,1) NOT NULL,");
		sb.append("[mobile] [varchar](30) NULL,");
		sb.append("[contact] [varchar](20) NULL,");
		sb.append("[call_status] [int] NULL,");
		sb.append("[call_time] [datetime] NULL,");
		sb.append("[call_billsec] [int] NULL,");
		sb.append("[call_uniqueid] [varchar](20) NULL,");
		sb.append("[tab_status] [int] NULL,");
		sb.append("[customer_id] [int] NULL,");
		sb.append("[extension] [int] NULL,");
		sb.append("[author] [int] NULL,");
		sb.append("[action_id] [varchar](20) NULL,");
		sb.append("[date_from_type] [char](12) NULL,");
		sb.append("[date_from_code] [varchar](32) NULL,");
		sb.append("[addtime] [datetime] NULL,");
		sb.append("[del] [int] NULL,");
		sb.append("[task_id] [int] NULL,");
		sb.append("[remark] [varchar](255) NULL,");
		sb.append("[address] [varchar](255) NULL");
		sb.append(")");
		Connection conn = null;
		Statement stat = null;
		try {
			Db db = Db.getDb();
			conn = db.getConnection();

			stat = conn.createStatement();

			// 创建表test
			stat.executeUpdate(sb.toString());
			stat.close();
			conn.close();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} finally {
			if (stat != null) {
				try {
					stat.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} finally {
					if (conn != null) {
						try {
							conn.close();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
						}
					}
				}
			}

		}

	}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值