WEB开发网
开发学院手机开发Android 开发 Android数据库相关代码解读之 SQLLite 阅读

Android数据库相关代码解读之 SQLLite

 2010-05-19 16:17:00 来源:WEB开发网   
核心提示:}}public boolean save(String name, String sex, Integer ages) {String sql = "insert into TestUser values(null,'" + name + "','" +

}

}

public boolean save(String name, String sex, Integer ages) {

String sql = "insert into TestUser values

(null,'" + name + "','" + sex

+ "'," + ages + ")";

try {

this.db.execSQL(sql);

Log.v(TAG, "insert Table TestUser 1 record ok");

return true;

} catch (Exception e) {

Log.v(TAG, "insert Table TestUser 1 record fail");

return false;

} finally {

//this.db.close();

Log.v(TAG, "insert Table TestUser ");

}

}

public Cursor loadAll() {

Cursor cur = db.query("TestUser", new String[]

{ "ID", "NAME","SEX","AGES"}, null,

null, null, null, null);

return cur;

}

public void open(Context context){

if (null == db || !this.db.isOpen()){

this.context = context;

this.db = context.openOrCreateDatabase(this.DataBaseName,

context.MODE_PRIVATE, null);

createTabel();

Log.v(this.TAG, "create or Open DataBase。。。");

}

}

public void close() {

db.close();

}

}

2) Android数据库交互代码

package com.topsun;

import android.app.Activity;

import android.database.Cursor;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

public class guiwindows extends Activity

implements OnClickListener {

EditText TEditname;

EditText TEditsex;

EditText TEditages;

EditText TEditmerge;

Button TSavebutton;

Button TViewbutton;

DBHelper db;

上一页  1 2 3 4  下一页

Tags:Android 数据库 相关

编辑录入:coldstar [复制链接] [打 印]
赞助商链接