Open JdbcTemplate connection in read-only mode?

Can I open a JdbcTemplate connection in read-only mode so that I cannot make any changes to the underlying data source?

+3
source share
3 answers

I do not believe the JDBC connectivity API allows this.

You have two options:

  • GRANT appropriate permissions for the database level to allow only SELECT operations;
  • Use Spring AOP and Security to intercept calls to record operations in the DAO and disallow them for specific roles.

The second choice is obviously more flexible and in the spirit of Spring’s natural idiom.

0
source

I am using a helper method like this

private void setConnectionReadOnly(boolean readOnly) {
    try {
        jdbcTemplate.getDataSource().getConnection().setReadOnly(readOnly);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
0
source

Source: https://habr.com/ru/post/1745963/


All Articles