我一直在做一个项目,我需要根据当前日期创建表名,以便每天根据日期创建新表。 我尝试像在 Sqlite 中一样应用它,但它不起作用。
总是报如下错误 [SQLITE_ERROR] SQL 错误或缺少数据库(靠近“20180215”:语法错误)
String s="create table if not exists "+LocalDate.now().toString().replaceAll("-","")+" ( id integer primany " +
"key autoincrement not null, sender text not null, receiever text not null, fathername" +
" text not null, money integer not null);";
LocalDate.now().toString().replaceAll("-","")
[SQLITE_ERROR] SQL 错误或缺少数据库(靠近“20180215”:语法错误)
最佳答案
除非强制,表名不能以数字开头。
您可以通过将表名括在 [table_name]
、'table_name'
、"table_name"
或 `table_name` 中来强制执行。
关于java - 如何在 Java 中将 LocalDate.now() 作为表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48805507/