1

I have MYSQL server hosted on a linux box. I am trying to access the server from my Java application. In the process, I came across an error message which is seemingly quite common with a resolution specified. I have tried the same at the Mysql server i.e. my.cnf and updated max_allowed_packet enter image description here and performed restart.

package com.test.ssh;

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


public class ConnectJDBC {

public static void main(String[] args) {
    
    
    String url = "jdbc:mysql://10.20.30.40:32/BI_data" ;
    String username = "testadmin";
    String password = "ServerABC";
    
    try {
        Connection connection = DriverManager.getConnection(url,username,password);
        
        System.out.println("Connected to the database");
    } catch (SQLException e) {
        System.out.println("Error!!");
        e.printStackTrace();
    }
    
    }

}

The error seen is

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.
at mysql.connector.java@8.0.26/com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:107)
at mysql.connector.java@8.0.26/com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
at mysql.connector.java@8.0.26/com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
at mysql.connector.java@8.0.26/com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
at mysql.connector.java@8.0.26/com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at com.test.ssh.ConnectJDBC.main(ConnectJDBC.java:18)

My ultimate aim is to connect over SSH the remote MySQL server. But this issue is blocking me in my pursuit. Any inputs on resolution will be very helpful.

VSTech
  • 77
  • 3
  • 11

0 Answers0