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

org.springframework.dao.TransientDataAccessResourceException:
### Error updating database.  Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: UPDATE wed_trans SET status=?, st_time=DATE_FORMAT(NOW(),‘%Y%m%d%H%i%S‘) WHERE order_no=?
### 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:106) ~[SQLStateSQLExceptionTranslator.class:4.0.9.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[AbstractFallbackSQLExceptionTranslator.class:4.0.9.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[AbstractFallbackSQLExceptionTranslator.class:4.0.9.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[AbstractFallbackSQLExceptionTranslator.class:4.0.9.RELEASE]

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

解决方法:事务配置在service层,但是你的service层的方法是query开头的,service调用的query方法根本就没有事务。你的配置文件下面是不是还有关于query*的配置成了read-only?修改你service方法的开头变成不是read-only的那种配置,如clear开头。(在query方法名(read_only)里面执行了update操作,所以就报错了。)

<!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

<!-- 声明式事物管理 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
                <tx:method name="get*" read-only="true" />
                <tx:method name="find*" read-only="true" />
                <tx:method name="load*" read-only="true" />
                <tx:method name="query*" read-only="true" />
                <tx:method name="add*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="save*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="insert*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="update*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="modify*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="delete*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="del*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="registe*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="approve*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="clear*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="set*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="reset*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <tx:method name="getUpdate*" read-only="false" rollback-for="Exception" propagation="REQUIRED"/>
                <!-- <tx:method name="*" read-only="true"/> -->
        </tx:attributes>
    </tx:advice>
时间: 2024-11-08 09:18:36

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed的相关文章

Connection is read-only. Queries leading to data modification are not allowed

<tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- 让所有的方法都加入事务管理,为了提高效率,可以把一些查询之类的方法设置为只读的事务 --> <!-- method name=*, readonly=true表示所有的数据库操作都可以使用,但是只能是读取数据库. 例如有UserService的方法 listUsers,

spring+struts+mybatis中关于报错org.hibernate.exception.GenericJDBCException: Connection is read-only. Queries leading to data modification are not allowed 的产生原因及解决方案

spring.xml:文件 1 <tx:advice id="txAdvice" transaction-manager="transactionManager"> 2 <tx:attributes> 3 <tx:method name="save*" propagation="REQUIRED" read-only="false" /> 4 <tx:method

Connection is read-only. Queries leading to data modification are not allowed 错误原因

因为我再spring 中使用了AOP进行事务管理,有如下配置 <tx:advice id="txAdvice" transaction-manager="transactionManager"> <!-- 定义事务传播属性 --> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:

java.sql.SQLException: connection holder is null 问题处理

问题描述 上上个周测试的时候突然报系统异常,于是我立即查看日志,发现是一个数据库异常:java.sql.SQLException: connection holder is null我第一想到的就是可能是那种概率很小的突发事件,然后就和测试说没关系只是数据库连接异常以后应该没事,然后项目因为更新重启后也没有什么问题,直到第二天有一次出现这个问题,这时候我才意识到这个不是突发事件.肯定是系统问题. 解决方案 发现问题后开始去网上找,结果发现是druid连接池的问题,而网上好多对于这种问题的解决方案

Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connectio

严重: StandardWrapper.Throwableorg.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

问题描述: 在使用JDBC连接数据库的时候,报错: java.sql.SQLException: Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 解决方案: 经检查,是由于连接的URL写错导致,原URL:"jdbc:oracle:thin:@localhost:152

JDBC报错 消息 Could not get JDBC Connection; nested exception is java.sql.SQLException: Unknown system variable &#39;tx_isolation&#39;

今天用JDBCTemplate时,发现启动服务器之后报错: Could not get JDBC Connection; nested exception is java.sql.SQLException: Unknown system variable 'tx_isolation'. 网上说是因为MySQL版本过高的问题,我的MySQL版本是8.0,里面已经没有tx_isolation,变成了transaction_isolation,用了以下几种解决方法: (1)更改MySQL  无效,仍然

java.sql.SQLException:ORA-24778:无法打开连接

weblogic日志中报:java.sql.SQLException:ORA-24778:无法打开连接.分析功能是有多次对远程表的操作,先查看关于db_link的参数: SQL> show parameter open_links NAME                                 TYPE        VALUE ------------------------------------ ----------- ------- open_links            

nested exception is java.sql.SQLException: IO 错误

1.错误描述 (mx.messaging.messages::ErrorMessage)#0 body = (null) clientId = "18CE3B03-9709-9DA8-7634-340C23317FDD" correlationId = "3161DF25-D056-D694-E5CF-963E4FE036D9" destination = "waitController" extendedData = (null) faultC