Packet for query is too large
Posted by: Sebastian Klute
Date: December 17, 2013 02:27AM


I hope you can help me.

I´m trying to use the MySQL-Database of my Webspace via Java. To do that I need to connect to the Webspace using a ssh-tunnel, I use JSch to do that an the Connections works.

To connect to the database I use Connector/J 5.1.27. Here is the code I use in Java:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db553?maxAllowedPacket=104857","user","pw");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Test");

I get the folowing error:

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.readPacket(
at com.mysql.jdbc.MysqlIO.doHandshake(
at com.mysql.jdbc.ConnectionImpl.coreConnect(
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(
at com.mysql.jdbc.ConnectionImpl.createNewIO(
at com.mysql.jdbc.ConnectionImpl.<init>(
at com.mysql.jdbc.JDBC4Connection.<init>(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(
at com.mysql.jdbc.ConnectionImpl.getInstance(
at com.mysql.jdbc.NonRegisteringDriver.connect(
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dbtest.main(

I only have a small Webspace, so I can not Change the "max_allowed_packet'" but with "maxAllowedPacket=104857" the error should not appear, or am I wrong? What is my mistake? The Error Occurs directly after the line:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db553?maxAllowedPacket=104857","user","pw");

So the System is only opening the Connection.

Any Ideas?

Kind Regards,

Options: ReplyQuote

Written By
Packet for query is too large
December 17, 2013 02:27AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.