把你的应用放在模拟器上跑一遍,然后从模拟器的data/data里面导一份出来看看!数据库是在data/data//databases下的,没有root权限取不出来的 查看原帖>>
android读取数据库可以使用sqlite一些api进行读取,实例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/
查找一条数据
@param uid
/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelpergetReadableDatabase(); //创建数据库辅助类
Cursor cursor =dbrawQuery("select from user where uid=", new String[]{uidtoString()}); //创建一个游标
if(cursormoveToFirst()){ //循环遍历查找数组
int uid2=cursorgetInt(cursorgetColumnIndex("uid"));
String uname=cursorgetString(cursorgetColumnIndex("uname"));
String uaddress=cursorgetString(cursorgetColumnIndex("uaddress"));
User user=new User();
usersetUid(uid2);
usersetUname(uname);
usersetUaddress(uaddress);
return user;
}
cursorclose();
return null;
}
*** 作方法是用FileInputStream读取原数据库,再用 FileOutputStream把读取到的东西写入到那个目录。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 packagecomandroidImportDatabase; importjavaioFile; importjavaioFileNotFoundException; importjavaioFileOutputStream; importjavaioIOException; importjavaioInputStream; importandroidcontentContext; importandroiddatabasesqliteSQLiteDatabase; importandroidosEnvironment; importandroidutilLog; publicclassDBManager { privatefinalintBUFFER_SIZE =400000; publicstaticfinalString DB_NAME ="countriesdb";//保存的数据库文件名 publicstaticfinalString PACKAGE_NAME ="comandroidImportDatabase"; publicstaticfinalString DB_PATH ="/data" + EnvironmentgetDataDirectory()getAbsolutePath() +"/" + PACKAGE_NAME; //在手机里存放数据库的位置 privateSQLiteDatabase database; privateContext context; DBManager(Context context) { thiscontext = context; } publicvoidopenDatabase() { thisdatabase =thisopenDatabase(DB_PATH +"/"+ DB_NAME); } privateSQLiteDatabase openDatabase(String dbfile) { try{ if(!(newFile(dbfile)exists())) { //判断数据库文件是否存在,若不存在则执行导入,否则直接打开数据库 InputStream is =thiscontextgetResources()openRawResource( Rrawcountries);//欲导入的数据库 FileOutputStream fos =newFileOutputStream(dbfile); byte[] buffer =newbyte[BUFFER_SIZE]; intcount =0; while((count = isread(buffer)) >0) { foswrite(buffer,0, count); } fosclose(); isclose(); } SQLiteDatabase db = SQLiteDatabaseopenOrCreateDatabase(dbfile, null); returndb; }catch(FileNotFoundException e) { Loge("Database","File not found"); eprintStackTrace(); }catch(IOException e) { Loge("Database","IO exception"); eprintStackTrace(); } returnnull; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 packagecomandroidImportDatabase; importjavautilArrayList; importandroidappActivity; importandroiddatabaseCursor; importandroiddatabasesqliteSQLiteDatabase; importandroidosBundle; publicclassTaxiActivityextendsActivity { privateSQLiteDatabase database; ArrayList CITY; @Override publicvoidonCreate(Bundle savedInstanceState) { superonCreate(savedInstanceState); setContentView(Rlayoutmain); database = SQLiteDatabaseopenOrCreateDatabase(DBManagerDB_PATH +"/"+ DBManagerDB_NAME,null); CITY = getCity(); // do something with CITY databaseclose(); } privateArrayList getCity() { Cursor cur = databaserawQuery("SELECT cityid_city, cityname FROM taxi, city WHERE cityid_city = taxiid_city GROUP BY cityid_city",null); if(cur !=null) { intNUM_CITY = curgetCount(); ArrayList taxicity =newArrayList(NUM_CITY); if(curmoveToFirst()) { do{ String name = curgetString(curgetColumnIndex("name")); intid = curgetInt(curgetColumnIndex("id_city")); CityClass city =newCityClass("",0); Systemoutprintln(name); //额外添加一句,把select到的信息输出到Logcat citycity_name = name; citycity_id = id; taxicityadd(city); }while(curmoveToNext()); } returntaxicity; }else{ returnnull; } } } 查看输出的结果:
以上就是关于android 手机里面应用的数据库如何取出来谢谢了,大神帮忙啊全部的内容,包括:android 手机里面应用的数据库如何取出来谢谢了,大神帮忙啊、Android中怎么读取返回报文的数据、Android如何导入已有的外部数据库(在raw下自己导入db文件)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)