简体   繁体   English

org.postgresql.util.PSQLException:错误:列“id”不存在 - Java Web 服务

[英]org.postgresql.util.PSQLException: ERROR: column "id" does not exist - Java Web Service

I am developing a java web service that is deployed in wildly.我正在开发一个广泛部署的 Java Web 服务。 It is connected to a postgresql database.它连接到一个 postgresql 数据库。 In this database, I have a table called xx_activity.在这个数据库中,我有一个名为 xx_activity 的表。 In it there is a column called "id", which is also the primary key.其中有一个名为“id”的列,它也是主键。 Here is the query used to create the table:这是用于创建表的查询:

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:错误:列“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,列名中没有尾随空格,也没有涉及任何大写字母(在这种情况下,另一个选择查询不应该起作用?)。

How can this be fixed?如何解决这个问题?

Fixed this, the issue was a missing space.解决了这个问题,问题是缺少空间。 After the first line of the query, there needs to be a space as belows:在查询的第一行之后,需要有一个空格,如下所示:

query = conn.prepareStatement("select id, baseitemid " +
                                            "from xx_activity " +
                                            "where \"id\" = ? ");

EDIT : escape charactors not needed for id ;编辑id不需要转义字符; so final answer should be:所以最终答案应该是:

 query = conn.prepareStatement("select id, baseitemid " +
                                                "from xx_activity " +
                                                "where id = ? ");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.postgresql.util.PSQLException:错误:列 systementi0_.id 不存在 - Hibernate、PostgreSql - org.postgresql.util.PSQLException: Error: column systementi0_.id does not exist - Hibernate, PostgreSql org.postgresql.util.PSQLException:错误:列 user0_.id 不存在 - Hibernate - org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist - Hibernate org.postgresql.util.PSQLException:错误:关系“序列”不存在 - org.postgresql.util.PSQLException: ERROR: relation “sequence” does not exist org.postgresql.util.PSQLException:错误:关系“产品”不存在 - org.postgresql.util.PSQLException: ERROR: relation "products" does not exist 引起:org.postgresql.util.PSQLException:错误:列 performanc3_.app_user_internal_user_id 不存在 - Caused by: org.postgresql.util.PSQLException: ERROR: column performanc3_.app_user_internal_user_id does not exist Java EE:org.postgresql.util.PSQLException:列不存在,但存在 - Java EE: org.postgresql.util.PSQLException: Column does not exist, while it does exists org.postgresql.util.PSQLException:错误:列 column0_.pk 不存在 Position:8 - org.postgresql.util.PSQLException: ERROR: column column0_.pk does not exist Position: 8 org.postgresql.util.PSQLException:错误:关系“clienti_id_seq”不存在 - org.postgresql.util.PSQLException: ERROR: the relation“clienti_id_seq” does not exist 错误:org.postgresql.util.PSQLException:错误:列 userinfo0_.dtype 不存在 - ERROR:org.postgresql.util.PSQLException:ERROR: column userinfo0_.dtype does not exist org.postgresql.util.PSQLException:致命:数据库“ postgres>”不存在 - org.postgresql.util.PSQLException: FATAL: database “postgres>” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM