Java Oracle 只读 JDBC 连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20287482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 00:51:36  来源:igfitidea点击:

Oracle read-only JDBC connection

javadatabaseoraclejdbc

提问by yannisf

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:

有没有办法从 oracle 数据库中获取只读 JDBC 连接。通常,我正在寻找一个 jdbc url 参数来启用它,例如:

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

I am using the thin driver

我正在使用瘦驱动程序

采纳答案by Abhijith Nagarajan

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.

您可以使用 connection.setReadOnly 在 Connection 类中设置 readOnly 参数。

Refer API docs for more details.

有关更多详细信息,请参阅 API 文档。

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

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

回答by chaos

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

据我所知,瘦驱动器将具有与您连接的用户相同的权限,因此,获取此权限的最简单方法是在数据库中拥有一个只读用户。检查此链接的最后一点:http: //docs.oracle.com/cd/B19306_01/java.102/b14355/apxtips.htm