SQLite 创建 查询 增加
2012-10-22 17:23
155 查看
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;
}
{
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;
}
相关文章推荐
- C语言实现链表的创建、增加、删除、查询、逆序、清空等基本操作
- 分别使用PreparedStatement和Statement对mysql数据库进行创建表,增加数据,查询数据和删除数据过程
- python学习—Day28—创建表、增加查询数据
- Sqlite的操作(增加,删除,查询,修改)
- python3-操作SQLite、创建表、添加数据、查询数据
- Sqlite的操作(增加,删除,查询,修改)
- python数据库sqlite基础(一)-------数据库创建,表的建立,数据录入,数据查询
- 终端查询数据库sqlite(创建你自己,或者是coredata创建)那里的东西
- Android 中SQlite数据中简单示例的表的创建、插入和查询
- Sqlite创建表一定要声明字段类型(ContentProvider查询的小问题)
- Sqlite的操作(增加,删除,查询,修改)
- C#使用linq to xml完成对XML文件的创建、增加、删除、修改、查询
- SQLite3(创建、插入、查询、更新数据库和表)
- DataTable 创建主键PrimaryKey 增加列,行,查询,主键查询
- 主从表的创建,查询代码待增加
- ios初学SQLite3(创建、插入、查询、更新数据库和表)
- Android-数据库Sqlite的创建,查询及在ListView显示
- SQLite创建自动增加时间的表
- ios初学SQLite3(创建、插入、查询、更新数据库和表)
- 用终端查询数据库sqlite(自己创建的,或者是用coredata创建的)里的东西