不多说,直接上代码,在自己成为高手之前看看~~嘿嘿

1,建表操作

db.execSQL("CREATE TABLE IF NOT EXISTS directions (dirTag STRING PRIMARY KEY, dirNameKey STRING, dirTitleKey STRING, dirRouteKey STRING)");            db.execSQL("CREATE TABLE IF NOT EXISTS routes (route STRING PRIMARY KEY, color INTEGER, oppositecolor INTEGER, pathblob BLOB)");            db.execSQL("CREATE TABLE IF NOT EXISTS stops (tag STRING PRIMARY KEY, lat FLOAT, lon FLOAT, title STRING)");            db.execSQL("CREATE TABLE IF NOT EXISTS stopmapping (route STRING, tag STRING, dirTag STRING, PRIMARY KEY (route, tag))");            db.execSQL("CREATE TABLE IF NOT EXISTS directionmapping (direction STRING, stop STRING, PRIMARY KEY(direction, stop))");            db.execSQL("CREATE TABLE IF NOT EXISTS IDX_directionmapping on directionmapping (direction)");            db.execSQL("CREATE INDEX IF NOT EXISTS IDX_routemapping ON stopmapping (route)");            db.execSQL("CREATE INDEX IF NOT EXISTS IDX_stopmapping ON stopmapping (tag)");

2,重新建表

db.execSQL("DROP TABLE IF EXISTS directions");            db.execSQL("DROP TABLE IF EXISTS routes");            db.execSQL("DROP TABLE IF EXISTS stops");            db.execSQL("DROP TABLE IF EXISTS stopmapping");            db.execSQL("DROP TABLE IF EXISTS directionmapping");            onCreate(db);


3,插入数据

private ContentValues values = null;

values.put("dirTag", direction.getDirTag());            values.put("dirNameKey", direction.getDirNameKey());            values.put("dirTitlekey", direction.getDirTitlekey());            values.put("dirRouteKey", direction.getDirRouteKey());            long id = db.insert("directions", null, values);


4,查询数据

private static final String DEFAULT_CURRENT_ROUTE_TAG = "select tag from stopmapping where route=?";    private static final String[] DEFAULT_CURRENT_SELECTION = new String[]{"751"}; Cursor c = db.rawQuery(querySQL, selection);
Cursor cursor = db.rawQuery("select count(*) as count from routes",null);


//----------------由一条路线得到该路线上的方向--------------------------------------------------------    public List<String> getDirection(String dirRouteKey){    directionList=new ArrayList<String>();    String selection="dirRouteKey="+dirRouteKey;    Cursor direction=db.query("directions",null, selection, null,null,null,null);    if(direction.moveToFirst()){    for(int i=0,num=direction.getCount();i<num;i++){    direction.moveToPosition(i);      directionList.add(direction.getString(direction.getColumnIndex("dirTag")));    }    }

                direction.close();                return directionList;}



更多相关文章

  1. Android(安卓)滚动事件 OnScrollListener
  2. android系统部分广播
  3. Android(java):database disk image is malformed (code 11)
  4. Android(安卓)Studio无线调试app之Android(安卓)WiFi ADB
  5. android链接rest services
  6. : Failed to read row 0, column -1 from a CursorWindow which
  7. SQLite数据库并发访问
  8. Android(安卓)sensor 实用篇
  9. Android共享数据ContentProvider的使用

随机推荐

  1. android:inputType参数类型说明
  2. android系统自带的主题与样式(theme and
  3. android:inputType参数类型说明
  4. android:inputType参数类型说明
  5. Android(安卓)控件和其基本属性1
  6. Android附带Theme总结
  7. Android系统自带样式(@android:style/)
  8. android按钮旋转简单实现
  9. android布局属性预览一
  10. android:inputType参数类型说明