-1

It continues to occur error... what is the problem? every variables are String.

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

Error message

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"]''))

My table has three column : ID(Integer), LABEL(TEXT), IMAGES(TEXT)

MikeT
  • 51,415
  • 16
  • 49
  • 68
baeharam
  • 543
  • 1
  • 8
  • 20

1 Answers1

0

Issue 1 you have specified a table name with a space i.e. LABELING RESULT, if this is the table name then you would need to enclose it e.g. [LABELING RESULT].

Issue 2 you have double single quotes when you should only have 1.

Issue 3 you have an extra closing parenthesis.

I believe the following is what you want :-

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"]'))

Which would (not checked though) be :-

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

That assumes that Sky goes into the LABEL column and the 2 comma separated image paths go into the IMAGES column.

Additional re enclosing (the [ ] ):-

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

MikeT
  • 51,415
  • 16
  • 49
  • 68
  • Does table name have to has bracket([])? – baeharam Aug 22 '18 at 09:43
  • Yes, or other valid enclosing characters (will update answer accordingly) if it has a space, although personally I would not use a space perhaps an underscore. e.g. LABELING_RESULT. – MikeT Aug 22 '18 at 09:46