I'm building a project using postgresql and java (NetBeans).
When I try to execute a simple query (select * from costumer) I get an error, telling me that "permission denied for relation costumer".
When I searched for an answer, all I found was about granting user privileges, so I went into pgAdmin and wrote "grant all privileges on database dirty to henrik;" . That didn't change anything - and that's why I'm making a new post..
The complete error message output of the program:
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)
The java program is really simple - it looks like this:
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...");
}
}
}
}
Privileges on the database are not enough.
You also need at least the USAGE
privilege for relevant schema and the SELECT
privilege for the table.
More details in this closely related answer:
How to grant all privileges on views to arbitrary user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With