SQLite 创建 查询 增加

public class UserDBHelper extends sqliteOpenHelper
{
private static String datebase_name = "user_datebase";
public static String table_name = "user_table";
public UserDBHelper(Context context,String name,CursorFactory factory,
int version) {
super(context,name,factory,version);
// Todo Auto-generated constructor stub
}
public UserDBHelper(Context c){
this(c,datebase_name,null,1);
System.out.println("userdb");
}
@Override
public void onCreate(sqliteDatabase db) {
// Todo Auto-generated method stub
System.out.println("enter oncreeat");
db.execsql("create table "+table_name+" (user_id integer primary key autoincrement,user_name text,user_pswd text)");
System.out.println("over oncreate");
}

@Override
public void onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) {
// Todo Auto-generated method stub
db.execsql("drop table "+table_name);
this.onCreate(db);
}


}

private void insertIP()
{

String ip=IP.getText().toString();
System.out.println("ip:"+ip);
ipdb db = new ipdb(IpActivity.this);
int type=db.getType();
System.out.println("type:"+type);

sqliteDatabase sd= db.getReadableDatabase();
String de="delete from "+ipdb.table_name ;
sd.execsql(de);
System.out.println("ip删除成功!");
sd.close();


sqliteDatabase sd1 = db.getWritableDatabase();
sd1.execsql("insert into "+ipdb.table_name+" values(null,?)",new String[]{ip});
sd1.close();
db.close();
HttpURL.setIpHttp(ip);
Toast.makeText(IpActivity.this,"保存成功!",Toast.LENGTH_SHORT).show();

}

private String getIP() { String ip=null; ipdb db = new ipdb(CybertronMainActivity.this); sqliteDatabase sd = db.getReadableDatabase(); Cursor c = sd.rawQuery("select ip_name from "+ipdb.table_name+"",null); while(c.movetoNext()){ ip = c.getString(0); System.out.println("ip:"+ip); } c.close(); sd.close(); db.close(); return ip; }

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能