Java SQL Table 带有特殊字符的名称

Java SQL Table names with Special characters

我有一个代码,可以即时创建 tables。这些 table 用于存储和获取不同进程的数据。

问题:Table 正在使用“&”等特殊字符创建名称。 MySQL 允许 table 个具有特殊字符的名称。 MySQL 不是问题。

当我使用 DBUtils 从 table 查询数据时,我在特殊字符处遇到异常。 如果我使用常规 jdbc,那么我可以转义那些并可以处理数据。但是 DBults 不允许转义这些字符。

我尝试在table名称中添加双引号并尝试处理,但问题仍然存在。有什么建议吗??

java.sql.SQLException: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right 
syntax to use near '-AO_I   ( Datetime,  L, ' at line 1 
    at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392)
    at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:491)
    at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:404)

正在删除所有列名称和详细的 table 名称。 table 名字是 "NRI-AO_I" 该代码将数据添加到数百个 table 中,但很少失败。这些 table 名称在 table 名称中具有特殊字符。 Table名称中包含“&”或“-”的失败。

在 table 名称中使用特殊字符是个坏主意,但如果您别无选择,请在您的模棱两可或 "special" table 名称中加上反引号。 例如:

select * from `NRI-AO_I`