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

Asked

Viewed 43 times

0

I wish my JDBC connection didn’t make queries that can make changes to tables (Insert, delete, update, drop). There’s some way this can be done?

  • 3

    I think it’s simpler to create a user who is only allowed to query in the database.

  • Which bank are you using?

  • True @rray, it’s even better to create a user in BD with access to queries only

1 answer

1

Rebeccamm,

  • First create a new user in your database
  • Give this user only the necessary 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 necessary permissions. As you did not inform your database check the code compatible for these operations.

I hope this helps...

Good Luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.