微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/sqlite/201701.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐