本文介绍了我如何设置max_allowed_pa​​cket'变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经开发了一个用于存储图像作为longblob的代码..所以它会完美地保存小jpgs吗? 我怎样才能增加图像容量? i有听说我需要在mysql上增加max_allowed_pa​​cket private void jButton4ActionPerformed(java.awt.event.ActionEvent evt){ { String Pass_No = jTF1.getText(); Object selectedItem1 = jCB1.getSelectedItem(); String CntryName1 = selectedItem1.toString(); Object selectedItem2 = jCB2.getSelectedItem(); String CntryName2 = selectedItem2.toString(); Object selectedItem3 = jCB3.getSelectedItem(); String CntryName3 = selectedItem3.toString(); java.util.Date sdate = jDC2.getDate(); String strDate = DateFormat.getDateInstance()。format(sdate); java.util.Date edate = jDC1.getDate(); String etrDate = DateFormat.getDateInstance()。format(edate); String Docs = jTF8.getText(); Connection connect = null; Statement statement = null; PreparedStatement perst = null; ResultSet resultSet = null; 尝试 { Class.forName( com.mysql.jdbc.Driver); connect = DriverManager.getConnection( jdbc:mysql:// localhost:3306 / userdb, root, ); File Imagefile = new 文件(jTF4.getText()); 文件Jpgfile = 新文件(jTF5.getText()); perst = connect.prepareStatement( 插入ppdata值(?,?,?,?,?, ????,,,)); FileInputStream fin1 = new FileInputStream(Imagefile); FileInputStream fin2 = new FileInputStream(Jpgfile); preSt.setString( 1 ,Pass_No); preSt.setString( 2 ,CntryName1); preSt.setString( 3 ,CntryName2); preSt.setString( 4 ,CntryName3); preSt.setString( 5 ,strDate); preSt.setString( 6 ,etrDate); preSt.setBinaryStream( 7 ,(InputStream)fin1,( int )Imagefile.length( )); preSt.setBinaryStream( 8 ,(InputStream)fin2,( int )Jpgfile.length( )); preSt.setString( 9 ,Docs); preSt.executeUpdate(); System.out.println( 已成功将文件插入数据库!); preSt.close(); connect.close(); } catch (例外e){ JOptionPane.showMessageDialog(null,e.getMessage()); } } } 我尝试过: i试过小图片?这将完美存储。 但更大的文件是不可能的?解决方案 参见 max_allowed_pa​​cket - Google搜索 [ ^ ]。 I have developed a code for store an image as a longblob.. so it will save small jpgs perfectly?how can i increase the image capacity?i have heard that i need to increase max_allowed_packet on mysqlprivate void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { { String Pass_No = jTF1.getText(); Object selectedItem1 = jCB1.getSelectedItem(); String CntryName1 = selectedItem1.toString(); Object selectedItem2 = jCB2.getSelectedItem(); String CntryName2 = selectedItem2.toString(); Object selectedItem3 = jCB3.getSelectedItem(); String CntryName3 = selectedItem3.toString(); java.util.Date sdate = jDC2.getDate(); String strDate = DateFormat.getDateInstance().format(sdate); java.util.Date edate = jDC1.getDate(); String etrDate = DateFormat.getDateInstance().format(edate); String Docs = jTF8.getText(); Connection connect = null; Statement statement = null; PreparedStatement preSt = null; ResultSet resultSet = null; try{ Class.forName("com.mysql.jdbc.Driver"); connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/userdb","root",""); File Imagefile = new File(jTF4.getText()); File Jpgfile = new File(jTF5.getText()); preSt=connect.prepareStatement("insert into ppdata values(?,?,?,?,?,?,?,?,?)"); FileInputStream fin1 = new FileInputStream(Imagefile); FileInputStream fin2 = new FileInputStream(Jpgfile); preSt.setString(1, Pass_No); preSt.setString(2, CntryName1); preSt.setString(3, CntryName2); preSt.setString(4, CntryName3); preSt.setString(5, strDate); preSt.setString(6, etrDate); preSt.setBinaryStream(7,(InputStream)fin1,(int)Imagefile.length()); preSt.setBinaryStream(8,(InputStream)fin2,(int)Jpgfile.length()); preSt.setString(9, Docs); preSt.executeUpdate(); System.out.println("Successfully inserted the file into the database!"); preSt.close(); connect.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null, e.getMessage()); } } } What I have tried:i have tried small images? that will store perfectly.but larger files are not possible? 解决方案 See max_allowed_packet - Google Search[^]. 这篇关于我如何设置max_allowed_pa​​cket'变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-24 21:50