欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android 访问SQLite

程序员文章站 2022-03-02 16:48:01
...
static SQLiteDatabase sld;
sld=SQLiteDatabase.openDatabase
				(
					"/data/data/com.bn.rcgl/myDb", 
					null, 
					SQLiteDatabase.OPEN_READWRITE|SQLiteDatabase.CREATE_IF_NECESSARY
				);
			String sql="create table if not exists type(tno integer primary key,tname varchar2(20));";
			sld.execSQL(sql);
			Cursor cursor=sld.query("type", null, null, null, null, null, "tno");
			int count=cursor.getCount();
			if(count==0)//如果是第一次运行程序,自动创建3个缺省类型
			{
				for(int i=0;i<father.defultType.length;i++)
				{
					sql="insert into type values("+i+",'"+father.defultType[i]+"')";
					sld.execSQL(sql);
				}
				
				cursor=sld.query("type", null, null, null, null, null, "tno");
				count=cursor.getCount();
			}
			alType.clear();
			while(cursor.moveToNext())
			{
				alType.add(cursor.getString(1));
			}
			sld.close();
			cursor.close();


http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CITy7klxxrJ35Nnc0biuQdjfLEM8uzKatFDeyBoh7SE6dSqDdi3pWAEfxisctECTUhdYJJ15S7iGFsMqZxql9zwMmTDicnHMwuOhc3p3IZUCd6h4%2Bs%3D