1.错误信息
- # java -cp postgresql-9.2-1001.jdbc4.jar:. Prepared
- Nov 13, 2012 5:07:38 PM Prepared main
- SEVERE: ERROR: permission denied for relation authors
- org.postgresql.util.PSQLException: ERROR: permission denied for relation authors
- at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
- at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
- at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
- at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
- at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
- at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363)
- at Prepared.main(Prepared.java:29)
2.原因
该数据库用户没有相应的权限。
在代码中,我们使用用户名(user12)及密码(user12)去连接PostgreSQL数据库。
- String user = "user12";
- String password = "user12";
再看看,我们数据库中所建表的归属,如下:
- testdb=# \dt
- List of relations
- Schema | Name | Type | Owner
- --------+---------+-------+----------
- public | authors | table | postgres
- public | books | table | postgres
- public | images | table | postgres
- public | testing | table | postgres
- (4 rows)
3.解决方法
修改使用的数据库用户,或则更改表的所属者。
- String user = "user12";
- String password = "user12";
或
- testdb=# ALTER TABLE authors OWNER TO user12;
阅读(4041) | 评论(4) | 转发(0) |