Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否以只读模式打开JdbcTemplate连接?_Java_Spring_Jdbc_Readonly_Jdbctemplate - Fatal编程技术网

Java 是否以只读模式打开JdbcTemplate连接?

Java 是否以只读模式打开JdbcTemplate连接?,java,spring,jdbc,readonly,jdbctemplate,Java,Spring,Jdbc,Readonly,Jdbctemplate,是否可以以只读模式打开JdbcTemplate连接,这样我就不能对底层数据源执行任何更改?我认为JDBC连接API不允许这样做 你有两个选择: 在上授予适当的权限 数据库级别仅允许选择 业务 使用SpringAOP和Security拦截在DAO上写入操作的调用,并禁止某些角色执行这些操作 第二种选择显然更加灵活,符合Spring的自然习惯用法。使用Spring事务并将事务声明为只读。请参见我使用这样的助手方法 private void setConnectionReadOnly(boolean

是否可以以只读模式打开JdbcTemplate连接,这样我就不能对底层数据源执行任何更改?

我认为JDBC连接API不允许这样做

你有两个选择:

  • 在上授予适当的权限 数据库级别仅允许选择 业务
  • 使用SpringAOP和Security拦截在DAO上写入操作的调用,并禁止某些角色执行这些操作

  • 第二种选择显然更加灵活,符合Spring的自然习惯用法。

    使用Spring事务并将事务声明为只读。请参见

    我使用这样的助手方法

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

    你说的是Spring框架吗?是的,我说的是Spring框架。