Reputation: 24005
We are using Java/Spring/Ibatis/MySql. Is there a way with these technologies to manage read-only connections at an application level. I am looking to add an extra layer of safeguarding on top of having read-only MySql users. It would be nice if BasicDataSource or SqlMapClientTemplate provided configuration for read-only connections. Otherwise, it seems like I'm left to only MySql read users and enforcing interfaces with only read methods.
Thanks
Upvotes: 3
Views: 7444
Reputation: 8534
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
Upvotes: 2
Reputation: 54810
Try to get the underlying java.sql.Connection
object and setReadOnly(true)
.
Upvotes: 1
Reputation: 109823
for example Connection#CreateStatement can takes parameters
statement = connection.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
Upvotes: 2