android 访问SQLite

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

猜你喜欢

转载自newton21012915.iteye.com/blog/1869545