Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 mysql

Java
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 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?
Posted
Updated 26-Feb-16 1:43am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900