嘿伙计们,我已经搜索了许多其他答案,但仍然无法弄清楚这个问题。
statement.executeUpdate("CREATE TABLE IF NOT EXISTS recentlyWatched (fileName STRING NOT NULL, fileLocation STRING, viewCount INTEGER, PRIMARY KEY (fileName))");
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:media.db");
statement = connection.createStatement();
statement.executeUpdate("INSERT INTO recentlyWatched (fileName, fileLocation, viewCount) VALUES ('"
+ fileName + "', '"
+ fileLocation + "', 0) ON DUPLICATE KEY UPDATE viewCount = '1'");
我尝试了多种方法来解决此问题,并且每当我尝试插入记录时都会感到茫然,我得到“java.sql.SQLException:接近“ON”:语法错误”。
更新
最终代码看起来像这样
statement.executeUpdate("INSERT OR IGNORE INTO recentlyWatched (fileName, fileLocation, viewCount) VALUES ('"
+ fileName + "', '"
+ fileLocation + "', 0)");
statement.executeUpdate("UPDATE recentlyWatched SET viewCount = viewCount + 1 WHERE '" + fileName + "' LIKE fileName;");