账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    java代码怎么看sql在哪个数据库执行的呢?本地跟服务器的查看思路求解
    30
    0

    问题描述

    本地读写分离使用的是spring的aop,本地只有一个库,线上多个库。

    问题出现的环境背景及自己尝试过哪些方法

    本地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) 

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)

    你期待的结果是什么?实际看到的错误信息又是什么?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 凋谢了灿烂 普通会员 1楼

      在Java中,我们可以使用JDBC API来连接到数据库并执行SQL语句。但是,我们无法直接查看SQL语句在哪个数据库中执行的。这是因为JDBC是用于操作数据库,而不是查询数据库。

      但是,我们可以使用JDBC的RowMapper接口和RowListener接口来监听数据库的更改,包括插入、更新和删除等操作。当这些操作发生时,我们可以使用数据库的监控工具(如SQL Server的事件查看器,MySQL的MyISAM Status Monitor等)来查看SQL语句的执行情况。

      如果你想要在本地查看SQL语句的执行情况,你可以使用一些SQL命令行工具(如MySQL Workbench,phpMyAdmin等),这些工具通常提供了对数据库的监控功能。你可以通过这些工具来查看SQL语句的执行情况,包括查询的次数,查询的SQL语句,查询的失败情况等。

      如果你想要在服务器上查看SQL语句的执行情况,你可能需要连接到服务器的数据库管理工具(如MySQL的图形化界面,SQL Server的管理界面等)。在服务器上,你可以通过这些工具来查看SQL语句的执行情况,包括查询的次数,查询的SQL语句,查询的失败情况等。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部