获取插入后生成的ID [英] Get generated id after insert

查看:117
本文介绍了获取插入后生成的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了Android SQLite的,我想知道拿到我插入的行的生成ID的最佳方式。

I'm using the SQLite with Android, and I want to know the best way to get the generated id of the row I inserted.

有一个解决方案,我认为这是使搜索包括后,但它不看的最好方法。

A solution I think is make a search after include, but it's doesn't look the best way.

推荐答案

的<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert%28java.lang.String,%20java.lang.String,%20android.content.ContentValues%29"><$c$c>insert方法返回 ID刚刚插入的行 1 如果有插入过程中出现错误。

The insert method returns the id of row just inserted or -1 if there was an error during insertion.

long id = db.insert(...);

其中db是 SQLiteDatabase

这篇关于获取插入后生成的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆