0

Here i am trying to connect my java file to mysql running on my live server..but after execution i got error "packet for query is too large"..i visited other post related to the question then i got the information to increase the max_allowed_size should be greater than the packet size..even after doing the same i am not able to resolve the error.

code that i tried.

import java.sql.*;

public class MySql {

public static void main(String args[]) {
    String dbURL = "jdbc:mysql://web-address:port-number/db";
    String username ="uname";
    String password = "pwd";

    Connection dbCon = null;
    Statement stmt = null;
    ResultSet rs = null;

    //System.out.println("connection successful"); 
   try {
        //getting database connection to MySQL server
        dbCon = DriverManager.getConnection(dbURL, username, password);

         System.out.println("connection successful"); 


    } catch (Exception ex) {
        System.err.println("Got an exception! ");
        System.err.println(ex.getMessage());
    } 

}  
}

error while execution is packet for query is too large (4739923>1048576). you can change this value on the server by setting the 'max_allowed_packet' variable.

TylerH
  • 20,799
  • 66
  • 75
  • 101
user3804161
  • 45
  • 2
  • 7
  • Can you run this SQL command somewhere: SHOW VARIABLES LIKE 'max_allowed_size'. This shows if you really changed the value of max_allowed_size. – mkabanen Feb 25 '15 at 10:53
  • And usually after changing the variable you should restart the server. Did you do that? – mkabanen Feb 25 '15 at 10:55
  • I increase the size of max_allowed_packet=15M..but its not working again giving the same error.. – user3804161 Feb 25 '15 at 10:56
  • yes i restart the server...after executing the SQL command SHOW VARIABLE LIKE 'MAX%' ..its showing me the changed size of packet.. – user3804161 Feb 25 '15 at 10:56
  • If it still gives exactly the same error, then the value of max_allowed_size isn – mkabanen Feb 25 '15 at 10:59
  • If it gives exactly the same error, then value of max_allowed_packet haven't been changed. Are you sure that the value is changed? – mkabanen Feb 25 '15 at 11:01
  • when i execute the sql command then it shows the changed size of packet...that means the value of max_allowed_packet=15728640 – user3804161 Feb 25 '15 at 11:04
  • Can you please give the exact error? – mkabanen Feb 25 '15 at 11:04
  • What are the Statement and ResultSet variables for? Are you really showing us the complete code you used? – Adriaan Koster Feb 25 '15 at 11:06
  • packet for query is too large (4739923>1048576). you can change this value on the server by setting the 'max_allowed_packet' variable. – user3804161 Feb 25 '15 at 11:06
  • actually the problem is in the connection..not able to connect to the server..apart from this if i am trying to connect using php i am successfully login to the mysql running on server...and able to fetch the table info...but here in java the connection is not established... – user3804161 Feb 25 '15 at 11:10
  • finally i got d solution...using http://stackoverflow.com/questions/13759418/com-mysql-jdbc-packettoobigexception/27303694#27303694 thank u.. – user3804161 Feb 26 '15 at 05:49

0 Answers0