2 hanbing521 hanbing521 于 2017.01.16 14:03 提问

java +mysql LOAD DATA INFILE mysql中执行正常,java报错???

LOAD DATA INFILE '/txt/test.txt' INTO TABLE test LINES TERMINATED BY '\r\n'
java.sql.SQLException: Could not retrieve transation read-only status server
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:877)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:873)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3603)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3572)
at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:759)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:739)
at LoadDateFile.main(LoadDateFile.java:45)
Caused by: java.sql.SQLException: Unknown system variable 'tx_read_only'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3597)
... 4 more

            public static void main(String[] args) {

    try {
        //System.out.println("start;");
        Class.forName("com.mysql.jdbc.Driver");
        //System.out.println("com.mysql;");
        conn = DriverManager.getConnection(url,user,password);
        System.out.println("conn:");
        stmt = conn.createStatement();
        // System.out.println("load date infile");
        String sql = "LOAD DATA INFILE  '/txt/test.txt'  INTO TABLE test  LINES TERMINATED BY '\\r\\n' ";
        //sql="SELECT * FROM test";
        // sql = "load data infile 'E:/mysqlsql/test.txt' replace into table test character set GBK fields terminated by ',' enclosed by '\'' lines terminated by '\r\n'";
        System.out.println(sql);
        boolean result = stmt.execute(sql);

        System.out.println("Load执行结果:" + result);

    }catch(Exception e){
        e.printStackTrace();
    }
}

2个回答

theUncle
theUncle   Rxr 2017.01.19 11:14
pm_mybook
pm_mybook   2017.01.20 17:17

LOAD DATA LOCAL INFILE 'test.txt' INTO TABLE test LINES TERMINATED BY '\r\n';改成这个试试

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!