How to limit a JDBC connection to only doing "select" queries?

0

I would like my JDBC connection to not make queries that can make changes to the tables (insert, delete, update, drop). Is there any way to do this?

    
asked by anonymous 17.02.2017 / 19:56

1 answer

1

RebeccaMM,

  • First create a new user in your database
  • Give this user only the required permissions, in your case only SELECT

Use the following code to perform the above operations:

CREATE USER username IDENTIFIED BY password;
GRANT CONNECT TO username;
GRANT SELECT no schema.table TO username;

And use the username / password created above when getting the JDBC connection. If other parts of the application need to insert, delete, or update, they can use another connection, configured with the required permissions. Since you did not enter your database, check the compatible code for these operations.

I hope this helps ...

Good Luck!

    
19.02.2017 / 21:12