SQLite 的应用实例

package com.gggeye;


import java.io.FileNotFoundException;
import java.util.ArrayList;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;

 

public class DataTest extends ListActivity {
    private final String _DB_NAME = "userdb";
    private final String _TABLE_NAME = "users";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        ArrayList<String> results = new ArrayList<String>();
        SQLiteDatabase db = null;
        try
        {
            //Log.log("中国");
            /* 新建 database */
            this.createDatabase(_DB_NAME, 1, MODE_PRIVATE, null);
            /* 打开 database */
            db = this.openDatabase(_DB_NAME, null);
            /* 新建 table */
            /* Create a Table in the Database. */
            db.execSQL("CREATE TABLE IF NOT EXISTS "
                                + _TABLE_NAME
                                + " (username VARCHAR, password VARCHAR,"
                                + " country VARCHAR, email VARCHAR);");
            /* 新建两笔资料 */
            db.execSQL("INSERT INTO "
                    + _TABLE_NAME
                    + " (username, password, country, email)"
                    + " VALUES ('Gramlich', 'Nicolas', 'Germany', 'Gramlich@mymobisoft.com');");
            db.execSQL("INSERT INTO "
                    + _TABLE_NAME
                    + " (username, password, country, email)"
                    + " VALUES ('Doe', 'John', 'US', 'Doe@mymobisoft.com');");
            Cursor c = db.query("SELECT username,password" +
                    " FROM " + _TABLE_NAME
                    + " WHERE country = 'US' LIMIT 2;",
                    null);
           
            /* 只取username 咄1 附件:  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值