当前位置: 首页 > 知识库问答 >
问题:

在java netbeans中向我的应用程序上传大图像

皇甫鸿远
2023-03-14

我正在创建一个应用程序。我想上传一个图像,并保存到我的数据库…当运行我的应用程序,它运行成功的小尺寸的图像,但我不能保存大尺寸的图像到我的数据库…当我要保存大尺寸的图像,如2兆,它提示一个错误,如

packetToObigException:用于查询的数据包太大(2491559>1048576)。您可以通过设置max_allowed_packet'变量在服务器上更改此值。

为什么会出现这样的错误…我怎么能用我的代码解决它呢

私有void jButton1ActionPerformed(java.awt.event.ActionEvent evt){

if (evt.getSource() == jButton1)
     {
        int x = 0;
        String s1 = jTextField1.getText().trim();
        String s2 = jTextField2.getText();

        char[] s3 = jPasswordField1.getPassword();
        char[] s4 = jPasswordField2.getPassword(); 
        String s8 = new String(s3);
        String s9 = new String(s4);

        String s5 = jTextField5.getText();
        String s6 = jTextField6.getText();
        String s7 = jTextField7.getText();

        if(s8.equals(s9))
        {
            try
            {
                File image1 = new File(filename);
        FileInputStream fis = new FileInputStream(image1);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        byte buf[] = new byte[1024];
        for (int readNum; (readNum = fis.read(buf)) != -1;) {

            bos.write(buf, 0, readNum);
        }
        cat_image = bos.toByteArray();
        System.out.println(cat_image.length);

            PreparedStatement ps = conn.prepareStatement("insert into reg values(?,?,?,?,?,?,?)");
                ps.setString(1, s1);
                ps.setString(2, s2);
                ps.setString(3, s8);
                ps.setString(4, s5);
                ps.setString(5, s6);
                ps.setString(6, s7);
                ps.setBytes(7, cat_image);
                int rs = ps.executeUpdate();
                x++;
                if (x > 0) 
                {
                    JOptionPane.showMessageDialog(jButton1, "Data Saved Successfully");
                }
            }
            catch(Exception e)
            {
                System.out.println(e);
            }
        }
        else
        {
            JOptionPane.showMessageDialog(jButton1, "Password Dosn't match");
        }

}
 else
{
    jTextField1.setText("");
        jTextField2.setText("");
        jPasswordField1.setText("");
        jPasswordField2.setText("");
        jTextField5.setText("");
        jTextField6.setText("");
        jTextField7.setText("");
}



// TODO add your handling code here:
}                                        
jTextField1.setText("");
        jTextField2.setText("");
        jPasswordField1.setText("");
        jPasswordField2.setText("");
        jTextField5.setText("");
        jTextField6.setText("");
        jTextField7.setText("");



// TODO add your handling code here:
}                                        

私有void jButton3ActionPerformed(java.awt.event.ActionEvent evt){

JFileChooser chooser = new JFileChooser();
    chooser.showOpenDialog(null);
    File f = chooser.getSelectedFile();
    filename = f.getAbsolutePath();
    jTextField3.setText(filename);


       // int returnVal = chooser.showOpenDialog(null);

    //if(returnVal == JFileChooser.APPROVE_OPTION) {

            ImageIcon icon=new ImageIcon(filename);
            jLabel8.setIcon(icon);

    //}




 // TODO add your handling code here:
 }

共有1个答案

仉成益
2023-03-14

正如异常所述,问题与服务器的max_allowed_packet变量有关,该变量定义了一个数据包的最大大小。请参见数据包太大主题,该主题描述如何修改服务器的配置文件以增加此变量的值。有关配置文件的更多详细信息,请参见使用选项文件。

 类似资料:
  • 我正在上传一个大的应用程序(大约250MB)。从家里,它在1个小时左右上传。 上载应用程序时出错。 服务器错误,状态代码:500,错误代码:0,消息: 有什么想法或建议吗?谢谢!

  • 我创建了一个应用程序,在Android marshmallow中崩溃,而在under版本中我的应用程序正常工作。 这怎么可能?这是我的清单代码: 这是分级代码: 我读到你必须在代码中修改一些东西,使其与AndroidMarshmallow兼容。 我该如何解决问题呢?

  • 我有一个目录Android应用程序,我正在建设,以展示不同的目录从不同的本地商店。目录基本上是图像(JPG)格式的页面。我希望每个商店都有自己的活动,推出一个目录。 请救命!

  • 我学习AWS和Flutter为大学的一个主题开发一个移动应用程序(Android),比如Instagram。 我的问题是,是否有一种方法可以直接将图像从应用程序发送到S3 Bucket,并将与该图像相关的URL存储在Dynamodb中。 我将感激任何形式的指导,因为我是AWS的新手。

  • 我有一个java应用程序,需要部署在weblogic服务器中。我目前正在为该应用程序制作ear文件。我的ear文件中有一个ejb jar。我想将log4j2 jar添加到此应用程序中。所以我的文件夹结构是 目前,我已经将JAR放在APP-INF文件夹/lib和META-INF/application中。xml我把JAR放在了模块中。这是我的申请表。xml 但它不接受log4j罐子。有什么解决方案吗

  • 我正在说明我的应用程序的一个奇怪问题。当我在真实设备(使用Android 4.4.4)上测试它时,我所有的按钮文本字段都看起来像我想要的(小写字母)。但是当我在模拟器(Android 5.0.1)上启动我的应用程序时,所有按钮文本字段都大写。这种行为的原因是什么?我应用程序中的一些示例按钮: 示例按钮 1: 示例按钮2: 这个问题的解决方案是什么。我希望我的应用在所有 sw 版本上看起来都一样。