Android的SQL:检查记录在数据库存在

编程入门 行业动态 更新时间:2024-10-28 08:29:45
本文介绍了Android的SQL:检查记录在数据库存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想基于一个特定ID来查询我的数据库。

字符串SQL =SELECT * FROM捣烂WHERE recipe_id ='+编号+'; 光标数据= database.rawQuery(SQL,NULL);

如果这是第一次的活动已经运行,该表将随着id列存在,但不会有与特定ID的记录。我如何检查是否该特定记录是否存在,如果它不增加吗?我发现很多到关于检查,如果一个特定的列存在,但没有任何有关检查,如果一个特定的记录存在。

到目前为止,我已经尝试获取ID列索引和检查,看它是否返回-1,但它实际上是返回1由于某种原因。我可以使用if语句来验证ID列尚未建立?

解决方案

如果(cursor.moveToFirst()){     //记录存在 } 其他 {     //没有找到记录 }

I am trying to query my database based on a specific id.

String sql = "SELECT * FROM mash WHERE recipe_id = '" + id + "'"; Cursor data = database.rawQuery(sql, null);

If this is the first time the activity has been run, the table WILL exist along with the id column, but there will not be a record with the specific id. How can I check if that specific record exists and if it does not, add it? I have found lots of into regarding checking if a specific column exists, but nothing about checking if a specific record exists.

So far I have tried getting the id column index and checking to see if it returns -1, but it actually is returning 1 for some reason. What can I use in an if statement to verify that the id column has not yet been created?

解决方案

if (cursor.moveToFirst()) { // record exists } else { // record not found }

更多推荐

Android的SQL:检查记录在数据库存在

本文发布于:2023-07-22 12:38:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Android   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!