Packet for query is too large (4739923 > 1048576)

今天连接mysql的数据库,报错,找了好久的问题原因,一直没找到,最终在stackoverflow上找到了一篇帖子,解决了我的问题
核心原因就是:应用服务器和数据库服务器在同一台主机上,
再代码中连接数据库的时候,就不要用主机的ip,而是用localhost

添加链接描述

I just had to deal with the same error message, thrown by DriverManager.getConnection(URL,username,password). I even got the same “magic numbers” (4739923 > 1048576); googling for those “magic numbers” will show results from people also getting the error thrown by some DriverManager.getConnection statement. In my case, the error message about packet size was COMPLETELY MISLEADING; I simply used a wrong URL, and the whole thing had to do NOTHING with packet size.

Maybe it will help to explain what was wrong with the URL I used - although this is kind of embarrassing (it’s kind of a very stupid mistake.) Here it goes.

I had successfully connected to the remote server/database with some “database manager” software called SQLYog (kind of like phpMyAdmin). In order to connect, I had to give SQLYog 2 sets of things. First, URL(or IP adress), username, password, and port, so that my computer can connect with the server. Second, URL, port, MySQL username, MySQL password, so that the server machine can connect to the database (located on that very machine.) So there were 2 URLs and also 2 ports (and also 2 usernames and 2 passwords) one for client -> server and one for server -> database.

Now, deciding on which URL to of those to pick for the JAVA code in DriverManager.getConnection, I picked the wrong one, stupid me! Obviously, that has to be the one for the second step (server -> database), not the first step (client -> server); after all the servlet runs on the server, so the fact that the servlet is even running shows that step 1 is already taken care of, and step 2 remains to be done. Since the database was on the same machine as the machine the servlet was running on, that url was just “localhost”; or, more exactly, “jdbc:mysql://localhost:3306/myDatabaseName”. And not “jdbc:mysql://domainNameOfServer.com:somePortNumber/myDatabaseName”, which threw above error.

Stupid mistake and very stupid error message. I guess that fits.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值