暑假第三周

Android中数据库的创建
• 数据库类:SQLite Database
• 数据库帮助类:SQLiteOpenHelper
方法一
• db = SQLiteDatabase.openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null)

方法二
• db = getContext().openOrCreateDatabase (DATABASE NAME, Context.MODE PRIVATE, null)
方法三
• db = SQLiteOpenHelper.getWritableDatabase()
• db = SQLiteOpenHelper.getReableDatabase()

执行SQL语句,这里是直接执行
• String sq| = "insert into tableName values (" 小华", "111");";
• db.execSQL(sql);

Android中封装好的SQL语句执行方法
•增加一条数据 db.insert(TABLE_ NAME, null, values);
•删除一条数据 db.delete(TABLE_ NAME, selection, selectionArgs)
•修改一条数据 db.update(TABLE_ NAME,values, selection,selectionArgs);
•查询一条数据 db.query(
TABLE_NAME, // The table to query
projection, //The array of columns to return (pass null to get all)
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order

);

posted @   超爱彬宝同学  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示