sqllite是轻量级的数据库,没有这种高可用性的功能。期待有经验的兄弟来解答下吧。
解决方案 »
- xml注释错误,大神来帮我解决一下吧。
- android 给GridView 一个监听 弹出Dialog为什么不能加按钮啊?
- android 视频h263编码
- 关于Eclipse开发中xml代码助手的问题:
- Eclipse中,如何查看函数声明的帮助文档?
- ? - 2.1的Launcher和1.6有什么不一样?
- android初学者 遇到一个小问题 请大家帮忙
- Canvas.drawText(text, x, y, paint)怎么设置要显示的文本“text"在x,y的左下角显示?
- listView的监听接收,进来看看吧
- 如何把pjsip通过jni移植到android上
- 如何监听输入法选择窗口?
- 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 语句 . 可具体不知道怎么用.