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

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值