使用 ODBC 转义包含问号的访问表名称 [英] Escape an access table name containing a question mark with ODBC

查看:47
本文介绍了使用 ODBC 转义包含问号的访问表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Access 数据库可以查询,如下所示:

I have an Access database to query as follows:

id - name - Print? 
1  - one  - Yes
2  - two  - No

现在我在 java 中的查询,使用 PreparedStatement 和一个 ODBC 连接器是这样的:

Now my query in java, using the PreparedStatement with an ODBC connector goes something like this:

select * from table where [Print?] = Yes

我找不到逃避问号的方法.我知道无论是谁创建了数据库,这是一个糟糕的设计选择,但它与已经改变它的应用程序如此紧密相连,这不是一个选择.

I can't find a way around this to escape the question mark. I know it's an awful design choice by whoever made the database, but it's so tied in applications already changing it is not an option.

附注.我读过 如何通过 ODBC 查询名称带有问号的 MS Access 列? 但这并没有回答我的问题.

PS. I've read How to query for a MS Access column whose name has a question mark, via ODBC? but this did not answer my question.

推荐答案

正如问题的评论中所建议的,显然唯一的解决方法是要么

As suggested in the comments to the question, apparently the only workaround is to either

  • 重命名 Access 表中的列以删除问号,或

  • rename the column in the Access table to remove the question mark, or

在 Access 中创建一个已保存的查询以返回具有不同名称的列,然后针对查询而不是表运行 JDBC 操作.

create a saved query in Access to return the column with a different name, and then run your JDBC operations against the query, not the table.

这篇关于使用 ODBC 转义包含问号的访问表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆