码迷,mamicode.com
首页 > 移动开发 > 详细

android中SQLite实现

时间:2016-05-05 17:37:32      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

SQLite操作类:

package com.example.administrator.myapplication;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class BookmarkSQLiteOpenHelper extends SQLiteOpenHelper{
    public BookmarkSQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
        super(context,name,factory,version);
    }

    @Override
    public void onCreate(SQLiteDatabase db){
        String sql="create table bookmark(id integer primary key autoincrement,favicon varchar(100),title varchar(100),url varchar(100))";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){}
}

SQLite初始化:

bookmarkSQLiteOpenHelper=new BookmarkSQLiteOpenHelper(this,"browser.db",null,1);

SQLite插入数据:

void insertBookmark(Bookmark bookmark){
        SQLiteDatabase db=bookmarkSQLiteOpenHelper.getWritableDatabase();
        db.execSQL("insert into bookmark(favicon,title,url)values(?,?,?)",new String[]{bookmark.getFavicon(),bookmark.getTitle(),bookmark.getUrl()});
    }

 

android中SQLite实现

标签:

原文地址:http://www.cnblogs.com/zqxLonely/p/5462549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!