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