How to manage read-only DB connections at an application level

别来无恙 提交于 2019-12-03 20:53:41

for example Connection#CreateStatement can takes parameters

statement = connection.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

BasicDataSource has a property called defaultReadOnly property to set it as readonly. You can use it.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://${db.host}:5432/${db.name}"/>
    <property name="username" value="${db.username}"/>
    <property name="password" value="${db.password}"/>
    <property name="defaultReadOnly" value="true"/>
</bean>

http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html

Try to get the underlying java.sql.Connection object and setReadOnly(true).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!