java - 列名称中包含 "é"的 iSeries JDBC Sql 语句抛出 java.sql.SQLException : [SQL0104]

标签 java sql jdbc ibm-midrange

我在从 SQL 查询返回的列名中使用字符“é”时遇到问题。运行此查询

SELECT PRCAT as Categorie, PRYEA as Année, PRDSC as Designation from DEMO.PRODUCT

使用 IBM Toolbox JDBC 驱动程序连接到 iSeries 会产生此异常:

 java.sql.SQLException: [SQL0104] Token é was not valid. Valid tokens: , FROM INTO. Cause . . . . . :   A syntax error was detected at token é.  Token é is not a valid token.  A partial list of valid tokens is , FROM INTO.  This list assumes that the statement is correct up to the token.  The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery  . . . :   Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token é. Correct the statement.  The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.
    at com.ibm.as400.access.JDError.throwSQLException(JDError.java:650)
    at com.ibm.as400.access.JDError.throwSQLException(JDError.java:621)
    at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1481)
    at com.ibm.as400.access.AS400JDBCPreparedStatement.<init>(AS400JDBCPreparedStatement.java:185)
    at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1903)
    at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1726)
...

这是 jdbc 驱动程序设置不正确的问题,还是对可以使用的字符存在一些内置限制(我在哪里可以找到这个?我发现 IBM doco 极其复杂......)。我的 jdbc 连接代码如下所示:

Class.forName("com.ibm.as400.access.AS400JDBCDriver").newInstance();
Connection cnnobj=DriverManager.getConnection("jdbc:as400://"+ipAddress+";errors=full;date format=iso;time format=iso;", user, pass);

最佳答案

如果引用别名会发生什么?

SELECT PRCAT as Categorie, PRYEA as "Année", PRDSC as Designation from DEMO.PRODUCT

关于java - 列名称中包含 "é"的 iSeries JDBC Sql 语句抛出 java.sql.SQLException : [SQL0104],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3687892/

相关文章:

java - Java中order by子句的SQL注入(inject)漏洞

java - 在 Heroku CI 期间启动应用程序

java - 在 JUnit 3 中,测试共享 Spring 容器吗?

sql - 是否有任何免费工具可以在 MS SQL Server 中生成 'INSERT INTO' 脚本?

sql - 查询计算连续事件之间的平均时间

c# - Entity Framework - 多列左外连接

mysql - 将数据库查询的值返回到 LinkedHashMap

java - 数据库中的编码问题

java - ImageView 不显示

Java 使用 selenium webdriver 处理上一页和元素