将大文件保存到数据库时遇到一些问题:
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_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();