求教SQLiteDatabase初始化的问题 本帖最后由 wlianghe00 于 2012-02-01 16:43:41 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SQliteOpenHelper是一个抽象类,来管理数据库的创建和版本的管理。要使用它必须实现它的nCreate(SQLiteDatabase),onUpgrade(SQLiteDatabase, int, int)方法 onCreate:当数据库第一次被建立的时候被执行,例如创建表,初始化数据等。 onUpgrade:当数据库需要被更新的时候执行,例如删除久表,创建新表。(Context getApplicationContext(),......); 在oncreate方法里面插入数据吗,那没有数据库的名字啊 onUpgrade:当数据库需要被更新的时候执行你说的插入应在这里 public class DBHelper extends SQLiteOpenHelper{final String CREATE_TABLE_SQL="create table Filter_Type(_id Integer primary key, filter_name,description)"; final String CREATE_TABLE_FILTER_SET="create table Filter_Set" + "(_id Integer primary key autoincrement, phone_num,link_man," + "filter_type,description);"; /** * 在数据库下创建表结构 */ @Override public void onCreate(SQLiteDatabase db) { if(db!=null){ //设置拦截号码数据库 //db.execSQL("create table Filter_Set(_id integer PRIMARY KEY AUTOINCREMENT,phone_num shrot,filter_type integer,description text)"); //拦截信息数据库 db.execSQL("create table Filter_Record(_id integer PRIMARY KEY AUTOINCREMENT, filter_num shrot,filter_time datatime,filter_content text,filter_mold integer,filter_read integer)"); //第一次使用数据库是自动创建表 db.execSQL(CREATE_TABLE_SQL);//拦截对象表 db.execSQL(CREATE_TABLE_FILTER_SET);//拦截设置表 db.execSQL("insert into Filter_Type(_id,filter_name) values(0,'来电+短信')"); db.execSQL("insert into Filter_Type(_id,filter_name) values(1,'来电')"); db.execSQL("insert into Filter_Type(_id,filter_name) values(2,'短信')");这不就加进去了 给你个链接 你看看就明白了http://code.google.com/p/androidlearn/wiki/SQLiteOpenHelper 特殊网页的用户登录界面无法输入用户登录信息 像来电通的这个功能怎么实现,有图 怎样使待机时保持gprs和wifi联网 android rild应用 跪求java使用webservice开发服务器端资料或源码 android动态设置edittext高度 求大神教怎样编辑一个helloworld的安卓项目啊 移动阅读器 struts2中使用JSON返回数据给安卓报错 关于android手机内存路径与SD卡路径的问题 新手入门android怎么查看android帮助文档 android如何连接计算机上的数据库
(Context getApplicationContext(),......);
在oncreate方法里面插入数据吗,那没有数据库的名字啊
public class DBHelper extends SQLiteOpenHelper{
final String CREATE_TABLE_SQL="create table Filter_Type(_id Integer primary key, filter_name,description)";
final String CREATE_TABLE_FILTER_SET="create table Filter_Set" +
"(_id Integer primary key autoincrement, phone_num,link_man," +
"filter_type,description);";
/**
* 在数据库下创建表结构
*/
@Override
public void onCreate(SQLiteDatabase db) {
if(db!=null){
//设置拦截号码数据库
//db.execSQL("create table Filter_Set(_id integer PRIMARY KEY AUTOINCREMENT,phone_num shrot,filter_type integer,description text)");
//拦截信息数据库
db.execSQL("create table Filter_Record(_id integer PRIMARY KEY AUTOINCREMENT, filter_num shrot,filter_time datatime,filter_content text,filter_mold integer,filter_read integer)");
//第一次使用数据库是自动创建表
db.execSQL(CREATE_TABLE_SQL);//拦截对象表
db.execSQL(CREATE_TABLE_FILTER_SET);//拦截设置表
db.execSQL("insert into Filter_Type(_id,filter_name) values(0,'来电+短信')");
db.execSQL("insert into Filter_Type(_id,filter_name) values(1,'来电')");
db.execSQL("insert into Filter_Type(_id,filter_name) values(2,'短信')");这不就加进去了
http://code.google.com/p/androidlearn/wiki/SQLiteOpenHelper