如何创建动态的SQLite数据库表
1个回答
2018-05-29 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
public FontDaoImpl(){
//在构造方法里边进行判断,看是否在sqlite里边有tb_font这张表,如果没有的话,在sqlite里面自动创建表
try {
conn = DBConnection.getConnection(Constants.DATABASE_PATH_STYLE);
final int cnt = conn
.prepareStatement(
"SELECT COUNT(*) as CNT FROM sqlite_master where type='table' and name='TB_FONT'")
.executeQuery().getInt(1);
if (cnt != 1) {
statement = conn.createStatement();
statement
.execute("CREATE TABLE TB_FONT (id integer primary key autoincrement, name NVARCHAR2(20),description NVARCHAR2(1000),fontSize number(20),textBorderColor NVARCHAR2(10),textBackgroundColor NVARCHAR2(10),textColor NVARCHAR2(10),isDefault NVARCHAR2(4))");
//statement.execute("CREATE UNIQUE INDEX id ON TB_CURVELINE (id)");
statement.close();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBConnection.closeConnection(conn);
}
}
//在构造方法里边进行判断,看是否在sqlite里边有tb_font这张表,如果没有的话,在sqlite里面自动创建表
try {
conn = DBConnection.getConnection(Constants.DATABASE_PATH_STYLE);
final int cnt = conn
.prepareStatement(
"SELECT COUNT(*) as CNT FROM sqlite_master where type='table' and name='TB_FONT'")
.executeQuery().getInt(1);
if (cnt != 1) {
statement = conn.createStatement();
statement
.execute("CREATE TABLE TB_FONT (id integer primary key autoincrement, name NVARCHAR2(20),description NVARCHAR2(1000),fontSize number(20),textBorderColor NVARCHAR2(10),textBackgroundColor NVARCHAR2(10),textColor NVARCHAR2(10),isDefault NVARCHAR2(4))");
//statement.execute("CREATE UNIQUE INDEX id ON TB_CURVELINE (id)");
statement.close();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBConnection.closeConnection(conn);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询