SQLite 初步使用

 1 public class AddressQueryDao {
 2     
 3     public static String queryAddr(String num){
 4         String addr="";
 5         
 6         File file = new File("data/data/com.example.mobilemangerii/address.db");
 7         SQLiteDatabase sqLiteDatabase = SQLiteDatabase.openDatabase(file.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);
 8         String regex = "^1\\d{10}";
 9         if (num.matches(regex)) {
10             Cursor cursor = sqLiteDatabase.rawQuery("select location from data2 where id=(select outkey from data1 where id=?)",    new String[]{num});
11             if (cursor.moveToNext()) {
12                 addr=cursor.getString(0);
13             }
14         }else if (num.length()==5) {
15             addr="客服电话";
16         }else {
17             System.out.println("AddressQueryDao.queryAddr()");
18         }
19         return addr;
20     }
21 }

 

posted @ 2015-06-17 17:01  月贝凡YBF  阅读(125)  评论(0)    收藏  举报