Android sqlite 数据库性能测试10万条数据

package com.yfs.testdb;

public class AppConstants {

    public static final String LOG_TAG = "testdb";

}

package com.yfs.testdb;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper{
    public static final String TABLE_NAME = "PersonTable";
    public static final String TABLE_NUMBER = "numbers";
    private static final String DATABASE_NAME = "test";
    private static final int DATABASE_VERSION = 2;
    private static final String TAG = "DatabaseHelper";

    // 构造函数,调用父类SQLiteOpenHelper的构造函数
    @SuppressLint("NewApi")
    public DatabaseHelper(Context context, String name, CursorFactory factory,
            int version, DatabaseErrorHandler errorHandler)
    {
        super(context, name, factory, version, errorHandler);

    }

    public DatabaseHelper(Context context, String name, CursorFactory factory,
            int version)
    {
        super(context, name, factory, version);
        // SQLiteOpenHelper的构造函数参数:
        // context:上下文环境
        // name:数据库名字
        // factory:游标工厂(可选)
        // version:数据库模型版本号
    }

    public DatabaseHelper(Context context)
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

        // 数据库实际被创建是在getWritableDatabase()或getReadableDatabase()方法调用时
        Log.d(AppConstants.LOG_TAG, "DatabaseHelper Constructor");
        // CursorFactory设置为null,使用系统默认的工厂类
    }

    // 继承SQLiteOpenHelper类,必须要覆写的三个方法:onCreate(),onUpgrade(),onOpen()
    @Override
    public void onCreate(SQLiteDatabase db)
    {
        // 调用时间:数据库第一次创建时onCreate()方法会被调用

        // onCreate方法有一个 SQLiteDatabase对象作为参数,根据需要对这个对象填充表和初始化数据
        // 这个方法中主要完成创建数据库后对数据库的操作

        Log.d(AppConstants.LOG_TAG, "DatabaseHelper onCreate");

        // 构建创建表的SQL语句(可以从SQLite Expert工具的DDL粘贴过来加进StringBuffer中)
        StringBuffer sBuffer = new StringBuffer();

        sBuffer.append("CREATE TABLE [" + TABLE_NAME + "] (");
        sBuffer.append("[_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ");
        sBuffer.append("[name] TEXT,");
        sBuffer.append("[age] INTEGER,");
        sBuffer.append("[info] TEXT)");
        String createTableNumberSql = "CREATE TABLE " + TABLE_NUMBER 
                + " (" +
                    "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
                    "number TEXT UNIQUE COLLATE NOCASE," +
                    "pos_wan INTEGER," +
                    "pos_qian INTEGER," +
                    "pos_bai INTEGER," +
                    "pos_shi INTEGER," +
                    "pos_ge INTEGER," +
                    "max_value INTEGER," +
                    "min_value INTEGER," +
                    "he_zhi INTEGER," +
                    "kua_du INTEGER," +
                    "is_shang_shan_number INTEGER," +
                    "is_xia_shan_number INTEGER," +
                    "xingtai_pos_wan_jiou INTEGER," +
                    "xingtai_pos_qian_jiou INTEGER," +
                    "xingtai_pos_bai_jiou INTEGER," +
                    "xingtai_pos_shi_jiou INTEGER," +
                    "xingtai_pos_ge_jiou INTEGER," +
                    "xingtai_pos_wan_zhihe INTEGER," +
                    "xingtai_pos_qian_zhihe INTEGER," +
                    "xingtai_pos_bai_zhihe INTEGER," +
                    "xingtai_pos_shi_zhihe INTEGER," +
                    "xingtai_pos_ge_zhihe INTEGER," +
                    "xingtai_pos_wan_012 INTEGER," +
                    "xingtai_pos_qian_012 INTEGER," +
                    "xingtai_pos_bai_012 INTEGER," +
                    "xingtai_pos_shi_012 INTEGER," +
                    "xingtai_pos_ge_012 INTEGER," +
                    "xingtai_012 TEXT," +
                    "xingtai_jiou TEXT," +
                    "xingtai_zhihe TEXT," +
                    "count_xingtai_ji INTEGER," +
                    "count_xingtai_ou INTEGER," +
                    "count_xingtai_0 INTEGER," +
                    "count_xingtai_1 INTEGER," +
                    "count_xingtai_2 INTEGER," +
                    "count_xingtai_zhi INTEGER," +
                    "count_xingtai_he INTEGER" +
                ");";
        // 执行创建表的SQL语句
        db.execSQL(sBuffer.toString());
        db.execSQL(createTableNumberSql);
        // 即便程序修改重新运行,只要数据库已经创建过,就不会再进入这个onCreate方法
        initTableNumber(db);
    }
    public void initTableNumber(SQLiteDatabase db){
        Log.d(AppConstants.LOG_TAG, "DBManager --> initTableNumber");
        // 采用事务处理,确保数据完整性
        db.beginTransaction(); // 开始事务
        try {
            long start = System.currentTimeMillis();
            for (int i=0; i < 100000; i++) {
                Number number = new Number();
                number.getNumber(i, number);
                db.execSQL("INSERT INTO " + DatabaseHelper.TABLE_NUMBER
                        + " VALUES(null, " +
                        "?," +
                        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
                        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
                        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { 
                        number.number ,
                        number.pos_wan ,
                        number.pos_qian ,
                        number.pos_bai ,
                        number.pos_shi ,
                        number.pos_ge ,
                        number.maxValue ,
                        number.minValue,
                        number.he_zhi ,
                        number.kua_du ,
                        number.is_shang_shan_number ,
                        number.is_xia_shan_number ,
                        number.xingtai_pos_wan_jiou ,
                        number.xingtai_pos_qian_jiou ,
                        number.xingtai_pos_bai_jiou ,
                        number.xingtai_pos_shi_jiou ,
                        number.xingtai_pos_ge_jiou ,
                        number.xingtai_pos_wan_zhihe ,
                        number.xingtai_pos_qian_zhihe ,
                        number.xingtai_pos_bai_zhihe ,
                        number.xingtai_pos_shi_zhihe ,
                        number.xingtai_pos_ge_zhihe ,
                        number.xingtai_pos_wan_012 ,
                        number.xingtai_pos_qian_012 ,
                        number.xingtai_pos_bai_012 ,
                        number.xingtai_pos_shi_012 ,
                        number.xingtai_pos_ge_012 ,
                        number.xingtai_012 ,
                        number.xingtai_jiou ,
                        number.xingtai_zhihe ,
                        number.count_xingtai_ji ,
                        number.count_xingtai_ou ,
                        number.count_xingtai_0 ,
                        number.count_xingtai_1 ,
                        number.count_xingtai_2 ,
                        number.count_xingtai_zhi ,
                        number.count_xingtai_he
                        });
                // 带两个参数的execSQL()方法,采用占位符参数?,把参数值放在后面,顺序对应
                // 一个参数的execSQL()方法中,用户输入特殊字符时需要转义
                // 使用占位符有效区分了这种情况
            }
            Log.d(TAG, "init number table takes " + (System.currentTimeMillis() - start));
            db.setTransactionSuccessful(); // 设置事务成功完成
        } finally {
            db.endTransaction(); // 结束事务
        }
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        // 调用时间:如果DATABASE_VERSION值被改为别的数,系统发现现有数据库版本不同,即会调用onUpgrade

        // onUpgrade方法的三个参数,一个 SQLiteDatabase对象,一个旧的版本号和一个新的版本号
        // 这样就可以把一个数据库从旧的模型转变到新的模型
        // 这个方法中主要完成更改数据库版本的操作

        Log.d(AppConstants.LOG_TAG, "DatabaseHelper onUpgrade");

        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NUMBER);
        onCreate(db);
        // 上述做法简单来说就是,通过检查常量值来决定如何,升级时删除旧表,然后调用onCreate来创建新表
        // 一般在实际项目中是不能这么做的,正确的做法是在更新数据表结构时,还要考虑用户存放于数据库中的数据不丢失

    }

    @Override
    public void onOpen(SQLiteDatabase db)
    {
        super.onOpen(db);
        // 每次打开数据库之后首先被执行

        Log.d(AppConstants.LOG_TAG, "DatabaseHelper onOpen");
    }

}

package com.yfs.testdb;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

//参考:http://blog.csdn.net/liuhe688/article/details/6715983
public class DBManager {
    private static final String TAG = "DBManager";
    private DatabaseHelper helper;
    private SQLiteDatabase db;

    public DBManager(Context context) {
        Log.d(AppConstants.LOG_TAG, "DBManager --> Constructor");
        helper = new DatabaseHelper(context);
        // 因为getWritableDatabase内部调用了mContext.openOrCreateDatabase(mName, 0,
        // mFactory);
        // 所以要确保context已初始化,我们可以把实例化DBManager的步骤放在Activity的onCreate里
        db = helper.getWritableDatabase();
        
    }

    /**
     * add persons
     * 
     * @param persons
     */
    public void add(List<Person> persons) {
        Log.d(AppConstants.LOG_TAG, "DBManager --> add");
        // 采用事务处理,确保数据完整性
        db.beginTransaction(); // 开始事务
        try {
            for (Person person : persons) {
                db.execSQL("INSERT INTO " + DatabaseHelper.TABLE_NAME
                        + " VALUES(null, ?, ?, ?)", new Object[] { person.name,
                        person.age, person.info });
                // 带两个参数的execSQL()方法,采用占位符参数?,把参数值放在后面,顺序对应
                // 一个参数的execSQL()方法中,用户输入特殊字符时需要转义
                // 使用占位符有效区分了这种情况
            }
            db.setTransactionSuccessful(); // 设置事务成功完成
        } finally {
            db.endTransaction(); // 结束事务
        }
    }

    /**
     * update person's age
     * 
     * @param person
     */
    public void updateAge(Person person) {
        Log.d(AppConstants.LOG_TAG, "DBManager --> updateAge");
        ContentValues cv = new ContentValues();
        cv.put("age", person.age);
        db.update(DatabaseHelper.TABLE_NAME, cv, "name = ?",
                new String[] { person.name });
    }

    /**
     * delete old person
     * 
     * @param person
     */
    public void deleteOldPerson(Person person) {
        Log.d(AppConstants.LOG_TAG, "DBManager --> deleteOldPerson");
        db.delete(DatabaseHelper.TABLE_NAME, "age >= ?",
                new String[] { String.valueOf(person.age) });
    }

    /**
     * query all persons, return list
     * 
     * @return List<Person>
     */
    public List<Person> query() {
        Log.d(AppConstants.LOG_TAG, "DBManager --> query");
        ArrayList<Person> persons = new ArrayList<Person>();
        Cursor c = queryTheCursor();
        while (c.moveToNext()) {
            Person person = new Person();
            person._id = c.getInt(c.getColumnIndex("_id"));
            person.name = c.getString(c.getColumnIndex("name"));
            person.age = c.getInt(c.getColumnIndex("age"));
            person.info = c.getString(c.getColumnIndex("info"));
            persons.add(person);
        }
        c.close();
        return persons;
    }

    /**
     * query all persons, return cursor
     * 
     * @return Cursor
     */
    public Cursor queryTheCursor() {
        Log.d(AppConstants.LOG_TAG, "DBManager --> queryTheCursor");
        Cursor c = db.rawQuery("SELECT * FROM " + DatabaseHelper.TABLE_NAME,
                null);
        return c;
    }

    /**
     * close database
     */
    public void closeDB() {
        Log.d(AppConstants.LOG_TAG, "DBManager --> closeDB");
        // 释放数据库资源
        db.close();
    }
    
}

package com.yfs.testdb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends Activity {

    private DBManager dbManager;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.listView);
        // 初始化DBManager
        dbManager = new DBManager(this);
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.hello_db, menu);
        return true;
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        dbManager.closeDB();// 释放数据库资源
    }

    public void add(View view)
    {
        ArrayList<Person> persons = new ArrayList<Person>();

        Person person1 = new Person("Ella", 22, "lively girl");
        Person person2 = new Person("Jenny", 22, "beautiful girl");
        Person person3 = new Person("Jessica", 23, "sexy girl");
        Person person4 = new Person("Kelly", 23, "hot baby");
        Person person5 = new Person("Jane", 25, "a pretty woman");

        persons.add(person1);
        persons.add(person2);
        persons.add(person3);
        persons.add(person4);
        persons.add(person5);

        dbManager.add(persons);
    }

    public void update(View view)
    {
        // 把Jane的年龄改为30(注意更改的是数据库中的值,要查询才能刷新ListView中显示的结果)
        Person person = new Person();
        person.name = "Jane";
        person.age = 30;
        dbManager.updateAge(person);
    }

    public void delete(View view)
    {
        // 删除所有三十岁以上的人(此操作在update之后进行,Jane会被删除(因为她的年龄被改为30))
        // 同样是查询才能查看更改结果
        Person person = new Person();
        person.age = 30;
        dbManager.deleteOldPerson(person);
    }

    public void query(View view)
    {
        List<Person> persons = dbManager.query();
        ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
        for (Person person : persons)
        {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("name", person.name);
            map.put("info", person.age + " years old, " + person.info);
            list.add(map);
        }
        SimpleAdapter adapter = new SimpleAdapter(this, list,
                android.R.layout.simple_list_item_2, new String[] { "name",
                        "info" }, new int[] { android.R.id.text1,
                        android.R.id.text2 });
        listView.setAdapter(adapter);
    }

    @SuppressWarnings("deprecation")
    public void queryTheCursor(View view)
    {
        Cursor c = dbManager.queryTheCursor();
        startManagingCursor(c); // 托付给activity根据自己的生命周期去管理Cursor的生命周期
        CursorWrapper cursorWrapper = new CursorWrapper(c)
        {
            @Override
            public String getString(int columnIndex)
            {
                // 将简介前加上年龄
                if (getColumnName(columnIndex).equals("info"))
                {
                    int age = getInt(getColumnIndex("age"));
                    return age + " years old, " + super.getString(columnIndex);
                }
                return super.getString(columnIndex);
            }
        };
        // 确保查询结果中有"_id"列
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_2, cursorWrapper,
                new String[] { "name", "info" }, new int[] {
                        android.R.id.text1, android.R.id.text2 });
        ListView listView = (ListView) findViewById(R.id.listView);
        listView.setAdapter(adapter);
    }

}

package com.yfs.testdb;

public class Number {
    public int _id;
    public String number;
    public int pos_wan;
    public int pos_qian;
    public int pos_bai;
    public int pos_shi;
    public int pos_ge;
    public int maxValue;
    public int minValue;
    public int he_zhi;
    public int kua_du;
    public int is_shang_shan_number;
    public int is_xia_shan_number;
    public int xingtai_pos_wan_jiou;
    public int xingtai_pos_qian_jiou;
    public int xingtai_pos_bai_jiou;
    public int xingtai_pos_shi_jiou;
    public int xingtai_pos_ge_jiou;
    public String xingtai_012;
    public String xingtai_jiou;
    public String xingtai_zhihe;
    public int count_xingtai_ji;
    public int count_xingtai_ou;
    public int count_xingtai_0;
    public int count_xingtai_1;
    public int count_xingtai_2;
    public int count_xingtai_zhi;
    public int count_xingtai_he;
    public int xingtai_pos_wan_zhihe;
    public int xingtai_pos_qian_zhihe;
    public int xingtai_pos_bai_zhihe;
    public int xingtai_pos_shi_zhihe;
    public int xingtai_pos_ge_zhihe;
    public int xingtai_pos_wan_012;
    public int xingtai_pos_qian_012;
    public int xingtai_pos_bai_012;
    public int xingtai_pos_shi_012;
    public int xingtai_pos_ge_012;
    
    public Number getNumber(int index, Number num) {
        num.pos_wan = index / 10000;
        num.pos_qian = (index % 10000) / 1000;
        num.pos_bai = (index % 1000) / 100;
        num.pos_shi = (index % 100) / 10;
        num.pos_ge = (index % 10);
        num.number = "" + num.pos_wan + num.pos_qian + num.pos_bai + num.pos_shi + num.pos_ge;
        num.he_zhi = num.pos_wan + num.pos_qian + num.pos_bai + num.pos_shi + num.pos_ge;
        num.maxValue = getMax(num);
        num.minValue = getMin(num);
        num.kua_du = num.maxValue - num.minValue;
        num.is_shang_shan_number = isShangShanNumber(num);
        num.is_xia_shan_number = isXiaShanNumber(num);
        num.xingtai_pos_wan_jiou = getNumberXingtaiJiou(num.pos_wan);
        num.xingtai_pos_qian_jiou = getNumberXingtaiJiou(num.pos_qian);
        num.xingtai_pos_bai_jiou = getNumberXingtaiJiou(num.pos_bai);
        num.xingtai_pos_shi_jiou = getNumberXingtaiJiou(num.pos_shi);
        num.xingtai_pos_ge_jiou = getNumberXingtaiJiou(num.pos_ge);
        
        num.xingtai_pos_wan_zhihe = getNumberXingtaiZhihe(num.pos_wan);
        num.xingtai_pos_qian_zhihe = getNumberXingtaiZhihe(num.pos_qian);
        num.xingtai_pos_bai_zhihe = getNumberXingtaiZhihe(num.pos_bai);
        num.xingtai_pos_shi_zhihe = getNumberXingtaiZhihe(num.pos_shi);
        num.xingtai_pos_ge_zhihe = getNumberXingtaiZhihe(num.pos_ge);
        
        num.xingtai_pos_wan_012 = getNumberXingtai012(num.pos_wan);
        num.xingtai_pos_qian_012 = getNumberXingtai012(num.pos_qian);
        num.xingtai_pos_bai_012 = getNumberXingtai012(num.pos_bai);
        num.xingtai_pos_shi_012 = getNumberXingtai012(num.pos_shi);
        num.xingtai_pos_ge_012 = getNumberXingtai012(num.pos_ge);
        
        num.xingtai_012 = getXingtai012(num);
        num.xingtai_jiou = getXingtaiJiou(num);
        num.xingtai_zhihe = getXingtaiZhihe(num);
        
        num.count_xingtai_0 = getCountXingtai0(num);
        num.count_xingtai_1 = getCountXingtai1(num);
        num.count_xingtai_2 = getCountXingtai2(num);
        
        num.count_xingtai_zhi = getCountXingtaiZhi(num);
        num.count_xingtai_he = 5 - num.count_xingtai_zhi;
        
        num.count_xingtai_ji = getCountXingtaiJi(num);
        num.count_xingtai_ou = 5 - num.count_xingtai_ji;
        //System.out.println(num);
        return num;
    }
    private int getCountXingtaiJi(Number num) {
        return num.xingtai_pos_wan_jiou 
                + num.xingtai_pos_qian_jiou
                + num.xingtai_pos_bai_jiou
                + num.xingtai_pos_shi_jiou
                + num.xingtai_pos_ge_jiou;
    }

    private int getCountXingtaiZhi(Number num) {
        return num.xingtai_pos_wan_zhihe
                + num.xingtai_pos_qian_zhihe
                + num.xingtai_pos_bai_zhihe
                + num.xingtai_pos_shi_zhihe
                + num.xingtai_pos_ge_zhihe;
    }
    private int getCountXingtai2(Number num) {
        int count = 0;
        if (num.xingtai_pos_wan_012 == 2){
            count++;
        }
        if (num.xingtai_pos_qian_012 == 2){
            count++;
        }
        if (num.xingtai_pos_bai_012 == 2){
            count++;
        }
        if (num.xingtai_pos_shi_012 == 2){
            count++;
        }
        if (num.xingtai_pos_ge_012 == 2){
            count++;
        }
        return count;
    }
    private int getCountXingtai1(Number num) {
        int count = 0;
        if (num.xingtai_pos_wan_012 == 1){
            count++;
        }
        if (num.xingtai_pos_qian_012 == 1){
            count++;
        }
        if (num.xingtai_pos_bai_012 == 1){
            count++;
        }
        if (num.xingtai_pos_shi_012 == 1){
            count++;
        }
        if (num.xingtai_pos_ge_012 == 1){
            count++;
        }
        return count;
    }
    private int getCountXingtai0(Number num) {
        int count = 0;
        if (num.xingtai_pos_wan_012 == 0){
            count++;
        }
        if (num.xingtai_pos_qian_012 == 0){
            count++;
        }
        if (num.xingtai_pos_bai_012 == 0){
            count++;
        }
        if (num.xingtai_pos_shi_012 == 0){
            count++;
        }
        if (num.xingtai_pos_ge_012 == 0){
            count++;
        }
        return count;
    }
    
    private String getXingtaiJiou(Number num) {
        StringBuffer sb = new StringBuffer();
        sb.append(num.xingtai_pos_wan_jiou == 0 ? "偶" : "奇");
        sb.append(num.xingtai_pos_qian_jiou == 0 ? "偶" : "奇");
        sb.append(num.xingtai_pos_bai_jiou == 0 ? "偶" : "奇");
        sb.append(num.xingtai_pos_shi_jiou == 0 ? "偶" : "奇");
        sb.append(num.xingtai_pos_ge_jiou == 0 ? "偶" : "奇");
        return sb.toString();
    }
    private String getXingtaiZhihe(Number num) {
        StringBuffer sb = new StringBuffer();
        sb.append(num.xingtai_pos_wan_zhihe == 0 ? "合" : "质");
        sb.append(num.xingtai_pos_qian_zhihe == 0 ? "合" : "质");
        sb.append(num.xingtai_pos_bai_zhihe == 0 ? "合" : "质");
        sb.append(num.xingtai_pos_shi_zhihe == 0 ? "合" : "质");
        sb.append(num.xingtai_pos_ge_zhihe == 0 ? "合" : "质");
        return sb.toString();
    }
    private String getXingtai012(Number num) {
        StringBuffer sb = new StringBuffer();
        sb.append(num.xingtai_pos_wan_012);
        sb.append(num.xingtai_pos_qian_012);
        sb.append(num.xingtai_pos_bai_012);
        sb.append(num.xingtai_pos_shi_012);
        sb.append(num.xingtai_pos_ge_012);
        return sb.toString();
    }

    private int getNumberXingtai012(int num) {
        switch (num) {
        case 1:
        case 4:
        case 7:
            return 1;
        case 2:
        case 5:
        case 8:
            return 2;
        case 0:
        case 3:
        case 6:
        case 9:
            return 0;
        default:
            break;
        }
        return -1;
    }
    private int getNumberXingtaiZhihe(int num) {
        switch (num) {
        case 0:
        case 4:
        case 6:
        case 8:
        case 9:
            return 0;
        case 1:
        case 2:
        case 3:
        case 5:
        case 7:
            return 1;
        default:
            break;
        }
        return -1;
    }
    private int getNumberXingtaiJiou(int num) {
        if (num % 2 == 0){
            return 0;
        }
        return 1;
    }
    private int isXiaShanNumber(Number num) {
        if (num.pos_wan > num.pos_qian && 
                num.pos_qian > num.pos_bai &&
                num.pos_bai > num.pos_shi && 
                num.pos_shi > num.pos_ge){
            return 1;
        }
        return 0;
    }
    private int isShangShanNumber(Number num) {
        if (num.pos_wan < num.pos_qian && 
                num.pos_qian < num.pos_bai &&
                num.pos_bai < num.pos_shi && 
                num.pos_shi < num.pos_ge){
            return 1;
        }
        return 0;
    }
    private int getMax(Number num) {
        int max = Math.max(num.pos_wan, num.pos_qian);
        max = Math.max(max, num.pos_bai);
        max = Math.max(max, num.pos_shi);
        max = Math.max(max, num.pos_ge);
        return max;
    }
    private int getMin(Number num) {
        int min = Math.min(num.pos_wan, num.pos_qian);
        min = Math.min(min, num.pos_bai);
        min = Math.min(min, num.pos_shi);
        min = Math.min(min, num.pos_ge);
        return min;
    }
    

    String createTableNumberSql = "CREATE TABLE number " + " ("
            + "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + "number TEXT UNIQUE COLLATE NOCASE," + "pos_wan INTEGER,"
            + "pos_qian INTEGER," + "pos_bai INTEGER," + "pos_shi INTEGER,"
            + "pos_ge INTEGER," + "he_zhi INTEGER," + "kua_du INTEGER,"
            + "is_shang_shan_number INTEGER," + "is_xia_shan_number INTEGER,"
            + "xingtai_pos_wan_jiou INTEGER,"
            + "xingtai_pos_qian_jiou INTEGER,"
            + "xingtai_pos_bai_jiou INTEGER," + "xingtai_pos_shi_jiou INTEGER,"
            + "xingtai_pos_ge_jiou INTEGER," + "xingtai_pos_wan_zhihe INTEGER,"
            + "xingtai_pos_qian_zhihe INTEGER,"
            + "xingtai_pos_bai_zhihe INTEGER,"
            + "xingtai_pos_shi_zhihe INTEGER,"
            + "xingtai_pos_ge_zhihe INTEGER," + "xingtai_pos_wan_012 INTEGER,"
            + "xingtai_pos_qian_012 INTEGER," + "xingtai_pos_bai_012 INTEGER,"
            + "xingtai_pos_shi_012 INTEGER," + "xingtai_pos_ge_012 INTEGER,"
            + "xingtai_012 TEXT," + "xingtai_jiou TEXT,"
            + "xingtai_zhihe TEXT," + "count_xingtai_ji INTEGER,"
            + "count_xingtai_ou INTEGER," + "count_xingtai_0 INTEGER,"
            + "count_xingtai_1 INTEGER," + "count_xingtai_2 INTEGER,"
            + "count_xingtai_zhi INTEGER," + "count_xingtai_he INTEGER" + ");";

    public Number() {
    }
    @Override
    public String toString() {
        return "Number [_id=" + _id + ", number=" + number + ", pos_wan="
                + pos_wan + ", pos_qian=" + pos_qian + ", pos_bai=" + pos_bai
                + ", pos_shi=" + pos_shi + ", pos_ge=" + pos_ge + ", maxValue="
                + maxValue + ", minValue=" + minValue + ", he_zhi=" + he_zhi
                + ", kua_du=" + kua_du + ", is_shang_shan_number="
                + is_shang_shan_number + ", is_xia_shan_number="
                + is_xia_shan_number + ", xingtai_pos_wan_jiou="
                + xingtai_pos_wan_jiou + ", xingtai_pos_qian_jiou="
                + xingtai_pos_qian_jiou + ", xingtai_pos_bai_jiou="
                + xingtai_pos_bai_jiou + ", xingtai_pos_shi_jiou="
                + xingtai_pos_shi_jiou + ", xingtai_pos_ge_jiou="
                + xingtai_pos_ge_jiou + ", xingtai_012=" + xingtai_012
                + ", xingtai_jiou=" + xingtai_jiou + ", xingtai_zhihe="
                + xingtai_zhihe + ", count_xingtai_ji=" + count_xingtai_ji
                + ", count_xingtai_ou=" + count_xingtai_ou
                + ", count_xingtai_0=" + count_xingtai_0 + ", count_xingtai_1="
                + count_xingtai_1 + ", count_xingtai_2=" + count_xingtai_2
                + ", count_xingtai_zhi=" + count_xingtai_zhi
                + ", count_xingtai_he=" + count_xingtai_he
                + ", xingtai_pos_wan_zhihe=" + xingtai_pos_wan_zhihe
                + ", xingtai_pos_qian_zhihe=" + xingtai_pos_qian_zhihe
                + ", xingtai_pos_bai_zhihe=" + xingtai_pos_bai_zhihe
                + ", xingtai_pos_shi_zhihe=" + xingtai_pos_shi_zhihe
                + ", xingtai_pos_ge_zhihe=" + xingtai_pos_ge_zhihe
                + ", xingtai_pos_wan_012=" + xingtai_pos_wan_012
                + ", xingtai_pos_qian_012=" + xingtai_pos_qian_012
                + ", xingtai_pos_bai_012=" + xingtai_pos_bai_012
                + ", xingtai_pos_shi_012=" + xingtai_pos_shi_012
                + ", xingtai_pos_ge_012=" + xingtai_pos_ge_012 + "]";
    }
    

}

package com.yfs.testdb;

public class Person {
    public int _id;
    public String name;
    public int age;
    public String info;

    public Person() {
    }

    public Person(String name, int age, String info) {
        this.name = name;
        this.age = age;
        this.info = info;
    }

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="add"
        android:text="add" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="update"
        android:text="update" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="delete"
        android:text="delete" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="query"
        android:text="query" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="queryTheCursor"
        android:text="queryTheCursor" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值