如何将大小为1gb的文件保存到mysql中?

lb3vh1jj  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(238)

我在将大文件保存到数据库时遇到一些问题:

Exception in thread "main" java.sql.SQLException: Parameter of prepared statement which is set through mysql_send_long_data() is longer than 'max_allowed_packet' bytes

我不想将“max\u allowed\u packet”的值设置为大小写,我们是否有办法使用java代码保存它。这是我的特征要求。class.forname(“com.mysql.jdbc.driver”);

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:1026/vistapoint_99_99_99", "root", "root");
        PreparedStatement prep = connection.prepareStatement("insert into appliancedebugfilechunk (file_id, chunk_size, file_chunk, seq_number) values(?,?,?,?)");
        File file = new File("D:\\Tool\\ideaIU-14.0.1.exe"); //278MB

        prep.setInt(1, 3);
        prep.setLong(2, file.length());
        prep.setInt(4, 10);

        prep.setBinaryStream(3, new FileInputStream(file), file.length());
        prep.executeUpdate();

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题