Chinaunix首页 | 论坛 | 博客
  • 博客访问: 42891
  • 博文数量: 7
  • 博客积分: 270
  • 博客等级: 入伍新兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-04 09:29
文章分类
文章存档

2012年(7)

分类: Java

2012-07-29 11:47:09

 8人阅读 评论(0) 收藏 举报
  1. package hhh.com;  
  2.   
  3. import android.content.ContentValues;  
  4. import android.content.Context;  
  5. import android.database.Cursor;  
  6. import android.database.sqlite.SQLiteDatabase;  
  7. import android.database.sqlite.SQLiteOpenHelper;  
  8.   
  9. public class bd extends SQLiteOpenHelper {  
  10.   
  11.   
  12.     public static String DB_NAME = "S.db";  
  13.     public static String ID = "_id";  
  14.     public static String T_NAME = "stu_list";  
  15.     public static int VERSION = 1;  
  16.     public static String NAME = "s_name";  
  17.     public static String IDCODE = "s_id";  
  18.     public static String *** = "s_***";  
  19.   
  20.   
  21.     public bd(Context context) {  
  22.         super(context, DB_NAME, null, VERSION);  
  23.     }  
  24.   
  25.   
  26.     @Override  
  27.     public void onCreate(SQLiteDatabase db) {  
  28.         // TODO Auto-generated method stub  
  29.         String sql = "create table " + T_NAME + " ( " + ID  
  30.                 + " integer primary key ," + IDCODE + " integer," + NAME  
  31.                 + " text," + *** + " text)";  
  32.         db.execSQL(sql);  
  33.     }  
  34.   
  35.   
  36.     @Override  
  37.     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  
  38.         // TODO Auto-generated method stub  
  39.         db.execSQL("drop table if exists" + T_NAME);  
  40.     }  
  41.   
  42.   
  43.     public long insert(int idcode, String name, String ***) {  
  44.         SQLiteDatabase db = getWritableDatabase();  
  45.         long row = 0;  
  46.         ContentValues cv = new ContentValues();  
  47.         cv.put(IDCODE, idcode);  
  48.         cv.put(NAME, name);  
  49.         cv.put(***, ***);  
  50.         row = db.insert(T_NAME, null, cv);  
  51.         return row;  
  52.     }  
  53.     public void delete(int id) {  
  54.         SQLiteDatabase db = getWritableDatabase();  
  55.         db.execSQL("delete from " + T_NAME + " where _id =" + id);  
  56.     }  
  57.   
  58.     public Cursor qurey(String name) {  
  59.         SQLiteDatabase db = getReadableDatabase();  
  60.         String sql = "select * from " + T_NAME + " where s_name = ?";  
  61.         Cursor cursor = db.rawQuery(sql, new String[] { name });  
  62.         return cursor;  
  63.     }  
  64.   
  65.     public int update(int _id, int id, String name, String ***) {  
  66.         SQLiteDatabase db = getWritableDatabase();  
  67.         ContentValues cv = new ContentValues();  
  68.         cv.put(IDCODE, id);  
  69.         cv.put(NAME, name);  
  70.         cv.put(***, ***);  
  71.         int flag = db.update(T_NAME, cv, ID + " = ? ",  
  72.                 new String[] { Integer.toString(_id) });  
  73.         return flag;  
  74.         // db.execSQL("update " + T_NAME  
  75.         // + " set s_id=? , s_name=? , s_***=? where _id=?", new Object[] {  
  76.         // id, name, ***, _id });  
  77.     }  
  78. }  


本文原创,转载请注明出处,谢谢合作!

阅读(2551) | 评论(1) | 转发(0) |
0

上一篇:ItemsControl删除元素,但仍然显示它们

下一篇:没有了

给主人留下些什么吧!~~

sijialgc2012-09-19 15:08:45

私家侦探 上海私家侦探 私人侦探 上海私人侦探 http://www.srzt8.com