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

1.问题描述

### Error updating database.  Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
### The error may involve com.webside.sso.mapper.SsoAccessTokenMapper.updateByPrimaryKeySelective-Inline
### The error occurred while setting parameters
### SQL: update sso_access_token      SET access_token = ?,                       user_id = ?,                       user_name = ?,                       ip = ?,                       client_id = ?,                       channel = ?,                       expires_in = ?,                       create_user = ?,                       create_time = ?,                       update_user = ?,                       update_time = ?      where id = ?
### 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] with root cause
java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1138)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3051)
    at com.alibaba.druid.wall.WallFilter.preparedStatement_execute(WallFilter.java:601)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049)
    at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049)
    at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049)
    at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049)
    at com.alibaba.druid.filter.FilterAdapter.preparedStatement_execute(FilterAdapter.java:1080)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049)
    at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:168)
    at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:494)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
    at com.sun.proxy.$Proxy77.execute(Unknown Source)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
    at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:52)
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
    at com.sun.proxy.$Proxy263.update(Unknown Source)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)

 

2.问题分析:

在spring-mybatis.xml中查看事务相关的配置


	
	
		
			
			
			
			
			
			
			
			
			
			
			
		
	


	
		
		
		
	

	
	

	
	

报错的方法所在的目录结果如下图所示:

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed_第1张图片

命名不符合规则的方法,如下图所示

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed_第2张图片

对应的实现类中如下图椭圆标注的代码,执行时报上述的异常信息

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed_第3张图片

3.解决方案:

分别修改service及impl中的createAccessToken为insertOrUpdateAccessToken,修改createRefreshToken为insertOrUpdateRefreshToken

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed_第4张图片

打断点并使用调试模式重启项目,再次执行指定业务逻辑操作,操作成功,如下图所示。

14:35:45.612 [http-nio-8090-exec-9] DEBUG updateByPrimaryKeySelective - ==>  Preparing: update sso_access_token SET access_token = ?, user_id = ?, user_name = ?, ip = ?, client_id = ?, channel = ?, expires_in = ?, create_user = ?, create_time = ?, update_user = ?, update_time = ? where id = ? 
14:35:46.172 [http-nio-8090-exec-9] DEBUG updateByPrimaryKeySelective - ==> Parameters: 11.5bc83e79ef1e59e85695b5de282dbc1e4f1cf3b6.2592000.1572158127(String), 1(Integer), admin(String), 127.0.0.1(String), 1(Integer), TEST_CLIENT1(String), 1572158127(Long), 1(Integer), 2018-08-30 17:33:26.0(Timestamp), 1(Integer), 2019-09-27 14:35:05.825(Timestamp), 2(Integer)
14:35:46.370 [http-nio-8090-exec-9] DEBUG updateByPrimaryKeySelective - <==    Updates: 1

java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed_第5张图片

你可能感兴趣的:(Java)