使用 Android 将图像路径存储到 SQLite 数据库时出错?

Error occurred while store image path to SQLite Database using Android?

它继续出现错误...有什么问题? 每个变量都是字符串。

String insertSQL = "INSERT INTO " + DBHelper.getTableName() + " VALUES (\''"+entry.getKey()+"\'', \''"+images+"\'')";

错误信息

INSERT INTO LABELING RESULT VALUES (''Sky'', ''["/storage/emulated/0/DCIM/CandyCam/IMG_20171009_164101723.jpg","/storage/emulated/0/DCIM/Pictail/IMG_20180305_000218777.jpg","/storage/emulated/0/DCIM/Pictail/IMG_20180401_235850170.jpg","/storage/emulated/0/DCIM/Pictail/IMG_20180518_194252232.jpg"]''))

我的 table 有三列:ID(Integer)、LABEL(TEXT)、IMAGES(TEXT)

问题 1 您指定了一个 table 名称和 space 即标签结果,如果这是 table 名称那么您需要将其括起来,例如[标签结果].

问题 2 你有双单引号,而你应该只有 1 个。

第 3 期你有一个额外的右括号。

我相信以下是你想要的:-

INSERT INTO [LABELING RESULT] VALUES ('Sky', '["/storage/emulated/0/DCIM/CandyCam/IMG_20171009_164101723.jpg","/storage/emulated/0/DCIM/Pictail/IMG_20180305_000218777.jpg","/storage/emulated/0/DCIM/Pictail/IMG_20180401_235850170.jpg","/storage/emulated/0/DCIM/Pictail/IMG_20180518_194252232.jpg"]'))

哪个(虽然未检查)是:-

String insertSQL = "INSERT INTO [" + DBHelper.getTableName() + "] VALUES ('"+entry.getKey()+"', '"+images+"')";

假定 Sky 进入 LABEL 列并且 2 个逗号分隔的图像路径进入 IMAGES 列。

附加重新封闭([ ] ):-

If you want to use a keyword as a name, you need to quote it. There are four ways of quoting keywords in SQLite:

  • 'keyword' A keyword in single quotes is a string literal.
  • "keyword" A keyword in double-quotes is an identifier.
  • [keyword] A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.
  • keyword A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.

SQL As Understood By SQLite - SQLite Keywords