java.sql.SQLException: Could not retrieve transation read-only status server

java代码连接mysql插入数据时,报以下错误: 
java.sql.SQLException: Could not retrieve transation read-only status server
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:951)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:941)
        at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3936)
        at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3907)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2408)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
        at ConnectionDemo.main(ConnectionDemo.java:23)
Caused by: java.sql.SQLException: Unknown system variable 'tx_read_only'
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2758)
        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)
        at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3930)
        ... 5 more


问题原因:mysql的jar文件版本与mysql数据库的版本不符,更换相应的mysql版本的驱动jar即可




你可能感兴趣的:(mysql)