How to manage read-only connections at the application level

We use Java / Spring / Ibatis / MySql. Is there a way to use these technologies to manage read-only connections at the application level. I want to add an extra layer of protection on top of read-only MySql users. It would be nice if BasicDataSource or SqlMapClientTemplate provided a configuration for read-only connections. Otherwise, it seems that I only need to read MySql users and use interfaces only with read methods.

thank

+3
source share
3 answers

for example Connection # CreateStatement can take parameters

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

BasicDataSource , defaultReadOnly, readonly. .

<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

+3

Try to get the base object java.sql.Connectionand setReadOnly(true).

+1
source

All Articles