Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Sqlite中使用where子句更新查询_Java_Android_Sqlite - Fatal编程技术网

Java 在Sqlite中使用where子句更新查询

Java 在Sqlite中使用where子句更新查询,java,android,sqlite,Java,Android,Sqlite,这是我在这个网站上的第一个问题。 我有一个关于更新查询的问题 ContentValues args = new ContentValues(); args.put("j_id", str); db.update(TABLE_NAME2, args, null, null); 我只想在其中添加where子句 像 那我该怎么办 您可以传递WHERE子句,而不是将null作为第三个参数传递 在您的情况下,这将如下所示: String value = "-1"; // Or someth

这是我在这个网站上的第一个问题。 我有一个关于更新查询的问题

  ContentValues args = new ContentValues();
  args.put("j_id", str);

  db.update(TABLE_NAME2, args, null, null);
我只想在其中添加where子句

那我该怎么办

您可以传递WHERE子句,而不是将null作为第三个参数传递

在您的情况下,这将如下所示:

String value = "-1"; // Or something else
String column = "j_id"; // The Column for the WHERE-clause
db.update(TABLE_NAME2, args, column+" = ?", new String[]{value});
WHERE j_id = '-1'
您应该始终使用prepared语句语法。因此,您实际上并没有在字符串中为WHERE子句添加值,而是使用第四个参数,该参数使用字符串数组替换WHERE子句?在WHERE查询字符串中

字符串数组的第一个元素替换为第一个?在查询字符串中,等等。最后,这创建了一个WHERE子句,如下所示:

String value = "-1"; // Or something else
String column = "j_id"; // The Column for the WHERE-clause
db.update(TABLE_NAME2, args, column+" = ?", new String[]{value});
WHERE j_id = '-1'

是的,我试过了,但没用。我是“Sqlite”的新手。你能写一行语法吗?期待中的感谢。我将此添加到我的原始答案中。因此,单击向上按钮并勾选绿色的勾号:D