往mysql裡面存MP3文件時,總是報
Exception in thread "main" com.mysql.jdbc.PacketTooBigException: Packet for query is too large (5406613 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3248)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1940)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2409)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312)
at mp3存取mysql.demo.main(demo.java:38)
經過排查錯誤,是默認mysql默認字段大小1048576小於我要上傳的MP3文件,所以報異常。
因為在windows下,所以去找mysql安裝目錄下的配置文件my.ini,進入後,要是有max_allowed_packet = 1M,則更改默認數值大小,要是沒有,則手動添加末尾(數值大小,自己設定),重新運行程序即可。