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,email)"
+ " VALUES ('Doe','John','US','Doe@mymobisoft.com');");
Cursor c = db.query("SELECT username,password" +
" FROM " + _TABLE_NAME
+ " WHERE country = 'US' LIMIT 2;",
null); 原文链接:https://www.f2er.com/sqlite/203192.html