title: How do I connect to MySQL Database located on a Namecheap server through java jdbc?
body: <pre><code>Packet for query is too large (4739923 &gt; 1048576). 
  You can change this value on the server by setting the max_allowed_packet' variable.
  </code></pre>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>Here is my code</p>
  
  <pre><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 = "&lt;My web server&gt;";
      String url = "jdbc:mysql://&lt;My Web Server&gt;:&lt;port&gt;/";
      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, &lt;port&gt;);
          session.setConfig(config);
          session.setPassword(hpass);
          session.connect();
          System.out.println("Connected through SSH");
          session.setPortForwardingL(3306, "127.0.0.1", &lt;port&gt;);
  
  
      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());
      }
  }
  }
  </code></pre>
  
  <p>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.</p>