关闭

android 数据库操作

356人阅读 评论(0) 收藏 举报
 private class DBOpenHelper extends SQLiteOpenHelper {
     private static final String name = "database.db";
     private static final int version = 1;
    
     public DBOpenHelper(Context context) {
     super(context, name, null, version);
     }
    
    
     @Override
     public void onCreate(SQLiteDatabase db) {
     db.execSQL("CREATE TABLE IF NOT EXISTS messgae (id integer primary key autoincrement, accountId long, folderId long,messageId long, kind int");
     }
    
     @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
     {
     db.execSQL("DROP TABLE IF EXISTS messgae");
     onCreate(db);
     }
    
     public long insert(long accountId,long folderId,long messageId,int kind){
     SQLiteDatabase db= getWritableDatabase();
     ContentValues cv = new ContentValues();
    
     cv.put(ACCOUNT_ID,accountId);
     cv.put(FOLDERP_ID, folderId);
     cv.put(MESSAGE_ID, messageId);
     cv.put(KIND, kind);
     return db.insert("messgae", null, cv);
     }
    
     public int getSelectedMessage(long accountId, long folderId,
     long messageId) {
     SQLiteDatabase db = getReadableDatabase();
    
     return db
     .query(
    
     "messgae",
    
     new String[] { "id" },
    
     "accountId = ? and folderId = ? and messageId = ?",
    
     new String[] { String.valueOf(accountId),
     String.valueOf(folderId),
     String.valueOf(messageId) }, null, null,
     "_id desc").getInt(0);
    
     }
    
     }


 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:126698次
    • 积分:1725
    • 等级:
    • 排名:千里之外
    • 原创:37篇
    • 转载:28篇
    • 译文:5篇
    • 评论:16条
    文章分类
    最新评论