加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLite 创建 查询 增加

发布时间:2020-12-12 20:25:06 所属栏目:百科 来源:网络整理
导读: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)

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; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读