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

时间:2018-12-12 08:07:54

标签: mysql blob

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

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_allowed_pa​​cket'的值,我们可以使用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();

0 个答案:

没有答案