利用小米数据库查找手机归属地
生活随笔
收集整理的這篇文章主要介紹了
利用小米数据库查找手机归属地
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
知識(shí)點(diǎn):
1 數(shù)據(jù)庫(kù)文件拷貝
2 使用SQLlite完成手機(jī)歸屬地查找
1?數(shù)據(jù)庫(kù)文件拷貝
/*** 將數(shù)據(jù)庫(kù)拷貝到getFilesDir()中* * @param dbName*/public void copyDB(String dbName) {InputStream in = null;FileOutputStream out = null;File file = new File(getFilesDir(), dbName);if (file.exists()) { //如果數(shù)據(jù)已經(jīng)存在,不進(jìn)行更新數(shù)據(jù)庫(kù)return;}try {in = getAssets().open(dbName);out = new FileOutputStream(file);int len = 0;byte[] buffer = new byte[1024];while ((len = in.read(buffer)) != -1) {out.write(buffer, 0, len);}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {try {in.close();out.close();} catch (Exception e) {e.printStackTrace();}}}address.db放在assets中:
經(jīng)過(guò)拷貝后,address.db放入在getFilesDir()+dbName(文件名address.db)中。
2?使用SQLlite完成手機(jī)歸屬地查找
package com.example.mobliesoft.Activity.DB;import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;public class AddressDao {public static final String PATH = "data/data/com.example.mobliesoft/files/address.db";public String getAddress(String phonenum) {String address = "未知號(hào)碼";//打開(kāi)數(shù)據(jù)庫(kù)SQLiteDatabase database = SQLiteDatabase.openDatabase(PATH, null, SQLiteDatabase.OPEN_READONLY);if (phonenum.matches("^1[3-8]\\d{9}$")) {//數(shù)據(jù)庫(kù)中查找數(shù)據(jù)Cursor cursor = database.rawQuery("select location from data2 where id=(select outkey from data1 where id=?)",new String[] { phonenum.substring(0, 7) });if (cursor.moveToNext()) {address = cursor.getString(0);}else{address="未知號(hào)碼";}cursor.close();} else {address="請(qǐng)輸入正確號(hào)碼";}database.close();return address;}}臥槽,先這樣吧,這塊兒真心不給力啊~
總結(jié)
以上是生活随笔為你收集整理的利用小米数据库查找手机归属地的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 关于营销自动化,30个惊人的事实
- 下一篇: 干货 | PCB设计中焊盘的种类和设计标