CRDU部分(不完全)
package db;标签:String,app7,sql,db,简单,import,password,id,记事本 From: https://www.cnblogs.com/yansans/p/17232228.html
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
//负责管理数据库的类,主要对表中的内容进行操作,CRUD
public class DBManager {
private static SQLiteDatabase db;
//初始化数据库
public static void initDB(Context context){
//得到帮助类对象
DBOpenhelper helper = new DBOpenhelper(context);
//得到数据库对象
db = helper.getWritableDatabase();
}
///////////////////////////////////////////////////////////////////////////////
//用户数据操作
//登录(查找)
public static Boolean getUserstart(String id, String password){
UserBean user = new UserBean();
String sql = "select * from user where id =? and password =?";
Cursor cursor = db.rawQuery(sql,new String[]{id, password});
if(cursor.moveToNext() == true){
cursor.close();
return true;
}
return false;
}
//注册检测
public static Boolean getUserlogin(String id, String name,
String uno, String classs, String phone, String password){
String sql = "insert into user (id, name, uno, classs, phone,password) values (?, ?, ?, ?, ?, ?)";
Object obj[]={id, name, uno, classs, phone, password};
db.execSQL(sql, obj);
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//事件数据操作
//添加事件
public static Boolean insertNote(String title, String keywords, String contents){
//自动获取系统时间
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy/MM/dd");
String daytime = sDateFormat.format(new java.util.Date());
String sql = "insert into note (title,keywords,contents,daytime) values (?, ?, ?, ?)";
Object obj[]={title, keywords, contents, daytime};
db.execSQL(sql, obj);
return true;
}
//全局浏览
//未实现
}