Max Myasoed
Max Myasoed

Reputation: 157

H2 database users

I'm using embeddable database H2 in my client-server application.

For some puposes I need to create user, that can only view tables without permission to change them. I supposed that creating non-admin user is enough for my situation. But I have the following exception trying to execute query SELECT * FROM ADDRESS:

org.h2.jdbc.JdbcSQLException: Недостаточно прав на объект "PUBLIC.ADDRESS"
Not enough rights for object "PUBLIC.ADDRESS"; SQL statement:
SELECT * FROM ADDRESS [90096-164] 
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) 
at org.h2.message.DbException.get(DbException.java:169) 
at org.h2.message.DbException.get(DbException.java:146) 
at org.h2.engine.User.checkRight(User.java:98) 
at org.h2.table.TableFilter.<init>(TableFilter.java:122) 
at org.h2.command.Parser.readTableFilter(Parser.java:1084) 
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1686) 
at org.h2.command.Parser.parseSelectSimple(Parser.java:1793) 
at org.h2.command.Parser.parseSelectSub(Parser.java:1680) 
at org.h2.command.Parser.parseSelectUnion(Parser.java:1523) 
at org.h2.command.Parser.parseSelect(Parser.java:1511) 
at org.h2.command.Parser.parsePrepared(Parser.java:405) 
at org.h2.command.Parser.parse(Parser.java:279) 
at org.h2.command.Parser.parse(Parser.java:251) 
at org.h2.command.Parser.prepareCommand(Parser.java:217) 
at org.h2.engine.Session.prepareLocal(Session.java:415) 
at org.h2.server.TcpServerThread.process(TcpServerThread.java:250) 
at org.h2.server.TcpServerThread.run(TcpServerThread.java:146) 
at java.lang.Thread.run(Unknown Source) 

at org.h2.engine.SessionRemote.done(SessionRemote.java:565) 
at org.h2.command.CommandRemote.prepare(CommandRemote.java:67) 
at org.h2.command.CommandRemote.<init>(CommandRemote.java:46) 
at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:437) 
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1121) 
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:164) 
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:152) 
at org.h2.server.web.WebApp.getResult(WebApp.java:1311) 
at org.h2.server.web.WebApp.query(WebApp.java:1001) 
at org.h2.server.web.WebApp$1.next(WebApp.java:964) 
at org.h2.server.web.WebApp$1.next(WebApp.java:967) 
at org.h2.server.web.WebThread.process(WebThread.java:166) 
at org.h2.server.web.WebThread.run(WebThread.java:93) 
at java.lang.Thread.run(Unknown Source)`

Is there are any approach to achieve the goal?

Upvotes: 4

Views: 9006

Answers (1)

Eggi
Eggi

Reputation: 1714

You have to grant the select right to the created user.

GRANT SELECT ON TEST TO READONLY

More information: http://www.h2database.com/html/grammar.html#grant_right

Upvotes: 4

Related Questions