jdbc包查询重载,无查询

brc7rcf0  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(267)

我试图连接到我的mysql数据库在远程服务器上,但我得到一个例外,查询是大的数据包。我甚至没有发任何查询。
com.mysql.cj.jdbc.exceptions.packettoobigexception:用于查询的数据包太大(4) 739 923 > 65 535). 您可以通过设置“max\u allowed\u packet”变量在服务器上更改此值。
代码:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Main {

static Connection connection = null;
static PreparedStatement preparedStatement = null;

public static void main(String[] argv) {

    try {
        makeJDBCConnection();
        preparedStatement.close();
        connection.close(); // connection close
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

private static void makeJDBCConnection() {

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        log("Couldn't found JDBC driver.");
        e.printStackTrace();
        return;
    }

    try {
        // DriverManager: The basic service for managing a set of JDBC drivers.
        connection = DriverManager.getConnection("jdbc:mysql://193.219.91.103:13667", "root", "root");
        if (connection != null) {
            log("Connection Successful! ");
        } else {
            log("Failed to make connection!");
        }
    } catch (SQLException e) {
        log("MySQL Connection Failed!");
        e.printStackTrace();
        return;
    }
}

private static void log(String string) {
    System.out.println(string);
    }
}
oipij1gg

oipij1gg1#

如果您有权访问服务器端,则必须更改mysql配置文件。看到了吗https://dev.mysql.com/doc/refman/5.6/en/option-files.html

相关问题