postgresql:关系的许可被拒绝

2022-09-04 03:43:56

我正在使用postgresql和java(NetBeans)构建一个项目。

当我尝试执行一个简单的查询(从客户中选择*)时,我收到一个错误,告诉我“关系客户的权限被拒绝”。

当我搜索答案时,我发现的只是关于授予用户权限的,所以我进入pgAdmin并写了“将数据库的所有权限都授予henrik;”。这并没有改变任何东西 - 这就是为什么我要写一个新帖子。

程序的完整错误消息输出:

run:
1
2
3

Mar 23, 2014 7:47:18 PM sletdendog.SletDenDog main
SEVERE: ERROR: permission denied for relation costumer
org.postgresql.util.PSQLException: ERROR: permission denied for relation costumer
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.executeQuery(AbstractJdbc2Statement.java:302)
at sletdendog.SletDenDog.main(SletDenDog.java:27)

BUILD SUCCESSFUL (total time: 0 seconds)

Java程序非常简单 - 它看起来像这样:

package sletdendog;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SletDenDog {

private static Connection connection = null;
private static PreparedStatement statement = null;
private static ResultSet result = null;
private static ResultSetMetaData meta = null;

public static void main(String[] args) {

    try{
        System.out.println("1");
        connection = DriverManager.getConnection("jdbc:postgresql://localhost/dirty", "henrik", "hokus pokus");
        System.out.println("2");
        statement = connection.prepareStatement("select * from costumer;");
        System.out.println("3");
        result = statement.executeQuery();
        System.out.println("4");
        meta = result.getMetaData();
        System.out.println("5");
        for (int i = 1; i <= meta.getColumnCount(); i++) {
            System.out.println(meta.getColumnName(i));
        }

    } catch (SQLException ex){
        Logger lgr = Logger.getLogger(SletDenDog.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);
    } finally {
        try{
            if(connection != null){
                connection.close();
            }
            if(statement != null){
                statement.close();
            }
            if(result != null){
                result.close();
            }
        } catch(SQLException ex){

            System.out.println("Something wasn't closed...");

        }
    }   
}   
}

答案 1

对数据库的权限是不够的。
您至少还需要相关架构的权限和表的权限。USAGESELECT

更多细节在这个密切相关的答案:
如何将视图的所有权限授予任意用户


答案 2

推荐