SQLite问题。 。 急 。 高手进 sqllite是轻量级的数据库,没有这种高可用性的功能。期待有经验的兄弟来解答下吧。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以前写的一个不知道能不能做参考import java.util.Date;import java.util.HashSet;import java.util.Set;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteException;import android.database.sqlite.SQLiteOpenHelper;import android.database.sqlite.SQLiteDatabase.CursorFactory;public class DBAdapter { private static final String DB = "Sample.db"; private static final String DB_CREATE_EXPEND = "create table Expend(ID integer primary key autoincrement,Type text,ExpendTime datatime,Amount real not null,Place text)"; private static final String DB_CREATE_INCOME = "create table Income(ID integer primary key autoincrement,Type text,IncomeTime datatime,Amount real not null)"; private Context context; private SQLiteDatabase db; private DBHelper dbHelper; public DBAdapter(Context context) { this.context = context; dbHelper = new DBHelper(context, DB, null, 1); open(); // createTable(); } // 数据库操作 public void open() { try { db = dbHelper.getWritableDatabase(); } catch (SQLiteException ex) { db = dbHelper.getReadableDatabase(); } } public void close() { db.close(); } public void insertExpend(Record newExpend) { db.execSQL("insert into Expend(Type,ExpendTime,Amount,Place)values('" + newExpend.Type + "','" + newExpend.Time.getTime() + "'," + newExpend.Amount + ",'" + newExpend.Place + "')"); } private Set<Record> searchExpend(String selection) { Set<Record> records = new HashSet<Record>(); Cursor cursor = db.query("Expend", new String[] { "ID", "Type", "ExpendTime", "Amount", "Place" }, selection, null, null, null, null); int Type = cursor.getColumnIndex("Type"); int ExpendTime = cursor.getColumnIndex("ExpendTime"); int Amount = cursor.getColumnIndex("Amount"); int Place = cursor.getColumnIndex("Place"); for (cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()) { Record newRecord = new Record(cursor.getString(Type), new Date( new Long(cursor.getString(ExpendTime))), new Double(cursor .getString(Amount)), cursor.getString(Place)); records.add(newRecord); } return records; } // 内部类 public class DBHelper extends SQLiteOpenHelper { public DBHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DB_CREATE_EXPEND); db.execSQL(DB_CREATE_INCOME); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // db.execSQL("drop table if exists User"); // onCreate(db); } }} 有个attach 语句 . 可具体不知道怎么用. 新手求助 为什么我在运行eclipse修改.xml文件后我的的内存一直在涨啊 跪求一个Android 2.1上的图片浏览器源码 请教一下android2.2和2.3上调用摄像头有什么不同??? 自定义适配器中,如何触发新开窗口--- startActivity() 什么是中国联通3G现网卡 android 横屏后如何确保数据不丢失。 数据库操作 android 布局的问题 一个android手机旅游软件需要用到什么技术 android studio的jni调试是怎么使用LLDB调试的 如何监听输入法选择窗口? android 闹钟 加入声音不响
import java.util.Date;
import java.util.HashSet;
import java.util.Set;import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;public class DBAdapter {
private static final String DB = "Sample.db";
private static final String DB_CREATE_EXPEND = "create table Expend(ID integer primary key autoincrement,Type text,ExpendTime datatime,Amount real not null,Place text)";
private static final String DB_CREATE_INCOME = "create table Income(ID integer primary key autoincrement,Type text,IncomeTime datatime,Amount real not null)"; private Context context;
private SQLiteDatabase db;
private DBHelper dbHelper; public DBAdapter(Context context) {
this.context = context;
dbHelper = new DBHelper(context, DB, null, 1);
open();
// createTable();
} // 数据库操作
public void open() {
try {
db = dbHelper.getWritableDatabase();
} catch (SQLiteException ex) {
db = dbHelper.getReadableDatabase();
}
} public void close() {
db.close();
} public void insertExpend(Record newExpend) {
db.execSQL("insert into Expend(Type,ExpendTime,Amount,Place)values('"
+ newExpend.Type + "','" + newExpend.Time.getTime() + "',"
+ newExpend.Amount + ",'" + newExpend.Place + "')");
} private Set<Record> searchExpend(String selection) {
Set<Record> records = new HashSet<Record>();
Cursor cursor = db.query("Expend", new String[] { "ID", "Type",
"ExpendTime", "Amount", "Place" }, selection, null, null, null,
null);
int Type = cursor.getColumnIndex("Type");
int ExpendTime = cursor.getColumnIndex("ExpendTime");
int Amount = cursor.getColumnIndex("Amount");
int Place = cursor.getColumnIndex("Place");
for (cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()) {
Record newRecord = new Record(cursor.getString(Type), new Date(
new Long(cursor.getString(ExpendTime))), new Double(cursor
.getString(Amount)), cursor.getString(Place));
records.add(newRecord);
}
return records;
}
// 内部类
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
} @Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DB_CREATE_EXPEND);
db.execSQL(DB_CREATE_INCOME);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// db.execSQL("drop table if exists User");
// onCreate(db);
}
}}
有个attach 语句 . 可具体不知道怎么用.