我正在使用postgresql和java(NetBeans)构建项目。
当我尝试执行一个简单的查询(从costumer中选择*)时,我收到一个错误,告诉我#34;关系客户"的权限被拒绝。
当我搜索答案时,我发现的所有内容都是关于授予用户权限,所以我进入了pgAdmin并编写了#34;将数据库脏的所有权限授予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...");
}
}
}
}
答案 0 :(得分:10)
数据库上的权限是不够的
您还需要至少相关模式的USAGE
权限和表的SELECT
权限。
这个密切相关答案的更多细节:
How to grant all privileges on views to arbitrary user