Re: Connect to MySQL: PacketTooGBigException
Posted by: Arthur Chan
Date: May 09, 2016 10:12AM

Here is the code, I've tried several variations, all reported the same error "PacketTooBigException".

As you can see, my session allowed packet size is many times bigger than than what I am sending or requesting.
public class LoadDriver {

	public static void main(String[] args) {

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

		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException ex) {
			System.out.println("Error: Cannot find MySQL JDBC Driver!\n");
			ex.printStackTrace();
			return;
		}
		System.out.println("MySQL JDBC Driver registered\n");
		try {
			conn = DriverManager
			.getConnection("jdbc:mysql://<ip-address>:21/dbName?maxAllowedPacket=1048576", "scott", "tiger");
			stmt = conn.createStatement();
			rs = stmt.executeQuery("SELECT project_name FROM test123 WHERE project_number = 678954321");
			while (rs.next()) {
				String projectName = rs.getString("project_name");
			}
		} catch (SQLException ex) {
			System.out.println("Connection to mysql failed, check output console!\n");
			ex.printStackTrace();
			return;
		} finally {
			try {
				if (rs != null)
					rs.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
			try {
				if (stmt != null)
					stmt.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
			try {
				if (conn != null)
					conn.close();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		}

		if (conn != null) {
			// TODO...
			System.out.println("You made it, you can take control of your database now\n");

		} else {
			System.out.println("Failed to connect to mysql!\n");
		}
	}
}


Options: ReplyQuote




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.