鍍金池/ 問答/Java  數(shù)據(jù)庫/ java代碼怎么看sql在哪個數(shù)據(jù)庫執(zhí)行的呢?本地跟服務(wù)器的查看思路求解

java代碼怎么看sql在哪個數(shù)據(jù)庫執(zhí)行的呢?本地跟服務(wù)器的查看思路求解

問題描述

本地讀寫分離使用的是spring的aop,本地只有一個庫,線上多個庫。

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

本地update沒問題,線上的時候報錯update的時候報錯read_only,報錯信息如下:
org.springframework.jdbc.UncategorizedSQLException: ### Error updating database. Cause: java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement ### The error may involve com.finance.core.acn.mapper.SequenceIDMapper.updateByPrimaryKeySelective-Inline ### The error occurred while setting parameters ### SQL: update t_increment_sequence SET current_value = ?, code = ? where id = ? ### Cause: java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement ; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1290]; The MySQL server is running with the --read-only option so it cannot execute this statement; nested exception is java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71) 
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:364) 
    at com.sun.proxy.$Proxy12.update(Unknown Source) 
    at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:250) 
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:49) 
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43) 
    at com.sun.proxy.$Proxy35.updateByPrimaryKeySelective(Unknown Source) 
    at com.finance.core.acn.service.impl.IDGeneratorServiceImpl.querySequenceNumPerMonth(IDGeneratorServiceImpl.java:54) 
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at com.sun.proxy.$Proxy36.querySequenceNumPerMonth(Unknown Source) 
    at com.finance.midware.acn.service.impl.BizSyncDataServiceImpl.generateBatchNo(BizSyncDataServiceImpl.java:1128) 
    at com.finance.midware.acn.service.impl.BizSyncDataServiceImpl.querySettleDataByBizSyncTypeAndDateRange(BizSyncDataServiceImpl.java:215) 
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at com.arch.db.aop.ReadMethodInterceptor.invoke(ReadMethodInterceptor.java:31) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at com.sun.proxy.$Proxy40.querySettleDataByBizSyncTypeAndDateRange(Unknown Source) 
    at com.finance.midware.schedule.dispatch.ProduceACNSettlementDataDispatch.generateInterfaceData(ProduceACNSettlementDataDispatch.java:109) 
    at com.finance.midware.schedule.dispatch.ProduceACNSettlementDataDispatch.execute(ProduceACNSettlementDataDispatch.java:76) 
    at com.schedule.AbsRunOnceScheduleTaskDeal.execute(AbsRunOnceScheduleTaskDeal.java:42) 
    at com.schedule.taskmanagerScheduleProcessorSleep.executeTaskScheduleProcessorSleep.java:342) 
    at com.schedule.taskmanagerScheduleProcessorSleep.runScheduleProcessorSleep.java:242) 
    at java.lang.Thread.run(Thread.java:748) 
Caused by: java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683) 
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144) 
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379) 
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2931) 
    at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440) 
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929) 
    at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:131) 
    at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493) 
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41) 
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66) 
    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45) 
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100) 
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75) 
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148) 
    at sun.reflect.GeneratedMethodAccessor457.invoke(Unknown Source) 
    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:354) 

相關(guān)代碼

// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)

你期待的結(jié)果是什么?實際看到的錯誤信息又是什么?

回答
編輯回答
呆萌傻

你這個是dataSource配置錯了吧,在只讀的庫執(zhí)行了update操作,所以報了這個錯,檢查一下配置文件和代碼應(yīng)該就能找到問題。我想問一下讀寫分離使用AOP是怎么一個實現(xiàn)方式?我之前做的項目是配置兩個數(shù)據(jù)源,MyBatis和Hibernate用不同的數(shù)據(jù)源。

2017年12月2日 02:10
編輯回答
空白格

想了下,只有日志吧

2017年7月30日 11:01