I am trying to connect to my MySQL database on remote server but I get an exception that query is to large for packet. I don't even sent any queries.
com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (4 739 923 > 65 535). You can change this value on the server by setting the 'max_allowed_packet' variable.
Code:
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);
}
}