Oracle read-only JDBC connection

18,091

Solution 1

As suggested in comments. Best is to grant the read only permissions to user accessing the database.

There is an alternative which is not suggested.

You can set the readOnly parameter in the Connection class using connection.setReadOnly.

Refer API docs for more details.

http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html#setReadOnly(boolean)

Solution 2

As far as I'm aware, the thin drive will have the same permissions as the user you're connected with will have, therefore, the easiest way to acquire this is by having a user in the database which is read-only. Check the last bit of this link: http://docs.oracle.com/cd/B19306_01/java.102/b14355/apxtips.htm

Share:
18,091

Related videos on Youtube

yannisf
Author by

yannisf

Developer

Updated on June 24, 2022

Comments

  • yannisf
    yannisf almost 2 years

    Is there a way to acquire read-only JDBC connection from an oracle database. Typically I am looking for a jdbc url parameter that will enable this, something like:

    jdbc:oracle:thin:@hostname:1521:sid?readonly=true
    

    I am using the thin driver

    • isnot2bad
      isnot2bad over 10 years
      Just specify a user that has right permissions only!
    • erencan
      erencan over 10 years
      You can do it with database grants not with connection url.
  • Stephen
    Stephen over 9 years
    Why is the read only "alternative" not suggested? Because of connection pooling or something?
  • Abhijith Nagarajan
    Abhijith Nagarajan over 9 years
    Sorry for the late reply. Setting readOnly attribute is not suggested as you have to do it while retrieving connection everytime. And, this is not a restriction and this setting is to give an hint to the driver to enable database optimizations.
  • Stoopkid
    Stoopkid about 6 years
    To clarify, setReadOnly(true) does not actually set the connection to read only as it might sound. It's not really an alternative at all if your goal is a connection that cannot modify the datasource.