0
Packet for query is too large (4739923 > 1048576). 
You can change this value on the server by setting the max_allowed_packet' variable.

This error is the end of me. On the server I'm trying to access, this max_allowed_packet is much larger than 1,048,576.

I have had a hell of a time solving this issue, resorting to as many forums as possible. It should be pretty simple. I want to connect to MySQL database on my namecheap server from a Java program on my computer. I have the IP address, the port for ssh. I can access the database totally and query from mySQL Workbench.

Here is my code

package testingdb;

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

import com.jcraft.jsch.Session;
import com.jcraft.jsch.JSch;
import com.mysql.jdbc.Driver;


public class DatabaseTesting {



public static void main(String[] args) {
    String huser = "user";
    String hpass = "*********";
    String userName = "username_user";
    String password = "*********";
    String host = "<My web server>";
    String url = "jdbc:mysql://<My Web Server>:<port>/";
    Session session= null;
    try {

        java.util.Properties config = new java.util.Properties(); 
        config.put("StrictHostKeyChecking", "no");

        JSch jsch = new JSch();
        session = jsch.getSession(huser, host, <port>);
        session.setConfig(config);
        session.setPassword(hpass);
        session.connect();
        System.out.println("Connected through SSH");
        session.setPortForwardingL(3306, "127.0.0.1", <port>);


    Class.forName("com.mysql.jdbc.Driver").newInstance();
    System.out.println("Logging into Database: "+ userName);
    Connection con = DriverManager.getConnection(url, userName, password);
    System.out.println("Server connected successfully");
    //Statement st = con.createStatement();
    //ResultSet results = st.executeQuery("SELECT * FROM NPC_DATA");
    //System.out.println(results);

    }
    catch(Exception e) {
        System.out.println("connection failed . . .");
        System.out.println(e.getMessage());
    }
}
}

My hpass and user and that are all correct when I type them in (I hid them for obvious reasons) I'm not sure what could go wrong. Help told me that Namecheap does not run with Java, but should this matter if my client is using JAVA to connect to the Server? Thank you so much.

1 Answers1

0

Could you try to change these lines?

    session.setPortForwardingL(<local port>, "<My web server>", <remote port>);

This will create a local port listening to remote port on your webserver. Now you need to make connection with your local port so url will change to:-

String url = "jdbc:mysql://localhost:<local port>/";
Mangat Rai Modi
  • 5,397
  • 8
  • 45
  • 75