安卓数据库操作insert中为什么非要用contentValues?

Darjeeling2011 2013-04-16 03:33:13
public long insert(User user) {
ContentValues values = new ContentValues();
values.put("name", user.username);
return dbInstance.insert(DB_TABLENAME, null, values);
}
...全文
522 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn_2013 2013-04-28
  • 打赏
  • 举报
回复
引用 6 楼 Darjeeling2011 的回复:
[quote=引用 4 楼 ConnectionUtils 的回复:] 引用 楼主 Darjeeling2011 的回复:public long insert(User user) { ContentValues values = new ContentValues(); values.put("name", user.username); return dbInstance.insert(DB_TABLENAM……
非常感谢。 还有这个contentValue网上说和java中的map机制很像,我不是很明白其中的奥妙,求解释[/quote] 呵呵意思就是说和Map使用的方法 语句结构 效果差不多 只是contentValue 实用于SQLlite数据库操作
Darjeeling2011 2013-04-18
  • 打赏
  • 举报
回复
引用 4 楼 ConnectionUtils 的回复:
引用 楼主 Darjeeling2011 的回复:public long insert(User user) { ContentValues values = new ContentValues(); values.put("name", user.username); return dbInstance.insert(DB_TABLENAM……
非常感谢。 还有这个contentValue网上说和java中的map机制很像,我不是很明白其中的奥妙,求解释
Darjeeling2011 2013-04-16
  • 打赏
  • 举报
回复
非常感谢。 还有这个contentValue网上说和java中的map机制很像,我不是很明白?
csdn_2013 2013-04-16
  • 打赏
  • 举报
回复
引用 楼主 Darjeeling2011 的回复:
public long insert(User user) { ContentValues values = new ContentValues(); values.put("name", user.username); return dbInstance.insert(DB_TABLENAME, null, values); } Android sqlite ……
没有非要用ContentValues 类的说法 只是android 提供了该api方便不会使用sql语句的开发人员也可以执行sql操作 直接写sql语句也是可以的

       String stmt ="UPDATE secure SET value='com.android.inputmethod.latin/.LatinIME' where name='default_input_method'";         
       db.execSQL(stmt); 
android_Y 2013-04-16
  • 打赏
  • 举报
回复
public void onCreate(SQLiteDatabase db) { db.execSQL("create table if not exists " + TAB_NAME + " (" + KEY_ID + " integer primary key," + KEY_RECORD + " integer," + KEY_LEVEL + " integer)"); } 比如可以这样写
Darjeeling2011 2013-04-16
  • 打赏
  • 举报
回复
请问怎么组成呢?我第一次接触数据库编程,之前学过简单的sql语句基础,请大侠明示啊。最好有代码演示的。谢过
android_Y 2013-04-16
  • 打赏
  • 举报
回复
你也可以自己组成SQL语句

80,361

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧