sqlite动态创建表,sqlite动态创建
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);
}
}