I am developing a java web service that is deployed in wildly. It is connected to a postgresql database. In this database, I have a table called xx_activity. In it there is a column called "id", which is also the primary key. Here is the query used to create the table:
我正在开发一个广泛部署的java web服务。它连接到postgresql数据库。在这个数据库中,我有一个名为xx_activity的表。其中有一个名为“id”的列,它也是主键。下面是用于创建表的查询:
CREATE TABLE xx_activity
(
id serial NOT NULL,
baseitemid integer
);
to connect to this table, I use the following java code:
要连接到这个表,我使用以下java代码:
conn = postgresVoyateDBConnection();
query = conn.prepareStatement("select id, baseitemid" +
"from xx_activity " +
"where \"id\" = ? ");
query.setInt(1, id);
ResultSet rs = query.executeQuery();
However, when I call the method that includes this code, I get an error:
但是,当我调用包含该代码的方法时,我得到一个错误:
org.postgresql.util.PSQLException: ERROR: column "id" does not exist
org.postgresql.util。PSQLException: ERROR:列“id”不存在。
Position: 8
位置:8
This is confusing because I certainly have this column. i added escape characters as per this answer, but it did not solve the issue.
这很令人困惑,因为我确实有这个列。我根据这个答案添加了转义字符,但它并没有解决这个问题。
Also note that queries without the where clause, like:
还要注意没有where子句的查询:
conn = postgresVoyateDBConnection();
query = conn.prepareStatement("select id, baseitemid " +
"from xx_activity");
ResultSet rs = query.executeQuery();
work perfectly.
完美的工作。
I have also tried without using escape characters but it gives the same error. I also checked in pgadmin and there is no trailing space in the column name, neither are there any upper case letters involved (in which case, the other select query shouldn't have worked?).
我也尝试过不使用转义字符,但它给出了相同的错误。我也检查了pgadmin,并且在列名中没有拖尾空间,也没有涉及任何大写字母(在这种情况下,另一个select查询不应该起作用)。
How can this be fixed?
这怎么可能是固定的呢?
1 个解决方案
#1
2
Fixed this, the issue was a missing space. After the first line of the query, there needs to be a space as belows:
修正了这个问题,这个问题是一个缺失的空间。在查询的第一行之后,需要有一个空格作为belows:
query = conn.prepareStatement("select id, baseitemid " +
"from xx_activity " +
"where \"id\" = ? ");
EDIT: escape charactors not needed for id
; so final answer should be:
编辑:不需要id的转义字符;所以最终的答案应该是:
query = conn.prepareStatement("select id, baseitemid " +
"from xx_activity " +
"where id = ? ");
#1
2
Fixed this, the issue was a missing space. After the first line of the query, there needs to be a space as belows:
修正了这个问题,这个问题是一个缺失的空间。在查询的第一行之后,需要有一个空格作为belows:
query = conn.prepareStatement("select id, baseitemid " +
"from xx_activity " +
"where \"id\" = ? ");
EDIT: escape charactors not needed for id
; so final answer should be:
编辑:不需要id的转义字符;所以最终的答案应该是:
query = conn.prepareStatement("select id, baseitemid " +
"from xx_activity " +
"where id = ? ");