### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are

Posted 一路追寻

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are相关的知识,希望对你有一定的参考价值。

Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

; SQL []; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
; SQL []; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
    at com.sun.proxy.$Proxy39.insert(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:253)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy52.saveV2(Unknown Source)

在进行修改数据库的时候出现了这个异常
很明显这个是只读引起的

可是事实上我们的数据账号权限很高,说明不是权限问题,说明是事务问题了
原因:你配置了只读事务
解决办法:

看下你的service层是否配置@Transactional(readOnly=true)
如果上面你没有配置的话,那就是spring切面引起的

在spring的配置文件中:

 <aop:config
  <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/>
    </aop:config>

    <!-- 事务的传播特性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="get*" propagation="REQUIRED" read-only="true"/>
        <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
        <tx:method name="query*" propagation="REQUIRED" read-only="true"/>
    </tx:attributes>

你是不是有类似于这样的,如果你的service方法名称是findpassword的话那么就会被拦截到了,然后就read-only了
所以改一下你的方法名称吧


或者在方法上添加注释
@Transactional(readOnly = false)

以上是关于### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are的主要内容,如果未能解决你的问题,请参考以下文章

教你如何让数据库支持emoji表情符存储

异常类Exception(String message, Throwable cause)中的cause理解

Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNot

关于Json在SSh框架中出现的问题

### Cause: java.lang.reflect.UndeclaredThrowableException

mysql报错:Cause: com.mysql.jdbc.PacketTooBigException