Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:52:07+00:00 2026-06-16T03:52:07+00:00

I am using BLOb support for inserting and reading from MySQl.(JDBC) I can do

  • 0

I am using BLOb support for inserting and reading from MySQl.(JDBC)
I can do that,but when it reads,its only few kb’s.I dont know why.
here is the working code:

 import java.sql.*;
import java.io.*;

public class InsertAndRetrieveImage {

 public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
  int id=7;
String connectionURL = "jdbc:mysql://127.0.0.1:3306/newdb";;
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "sesame");

 PreparedStatement ps = null;

 ps=con.prepareStatement("INSERT IGNORE INTO image VALUES(?,?,?)");

         File file = new File("e:/anarkali.wav");


         FileInputStream fs = new FileInputStream(file);

     try{
        System.out.println(fs.available());
         ps.setInt(1,id);
         ps.setBinaryStream(2,fs,fs.available());
         String filen=file.getName();
      ps.setString(3,filen);


      int i = ps.executeUpdate();



        String filename="filename";OutputStream os=null;byte[] content=null;
        ps= con.prepareStatement("SELECT fs from image where id=7");
        ResultSet rs = ps.executeQuery();
         System.out.println(rs);
      while(rs.next()) {


            Blob blob = rs.getBlob("fs");

        content = blob.getBytes(1, (int) blob.length());


        os = new FileOutputStream(new File("e://testanar.wav"));

    }
    os.write(content);
    os.close();
    con.close();
    ps.close();}
     catch(SQLException e)
     {System.out.println(e.getMessage());
     }

  }catch(Exception ex){}


  }

Is the problem while reading or writing?my BLOb’s size is somewhat 65535.Is this is the bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:52:08+00:00Added an answer on June 16, 2026 at 3:52 am

    Your program is correct. If the file size is small then it will work fine. If you are using BLOB datatype to store that binary data,change it to LONGBLOB. Because if you tried to save a file in BLOB data field, and if the file size is more than max allowed size of BLOB datatype then the content will be truncated and you will loss some content of file(depends on file size). Even if you use LONGBLOB datatype there are some things you must check. I’ll explain

    In mysql website we can see that max file size of LONGBLOB is 4GB. But it depends on many things. To store large file you have to check some things. First thing is in my.ini file, there is a property called max_allowed_packet, it specifies largest possible packet that can be transmitted to or from a mysql client or server. You should set max_allowed_packet property to a higher value. And restart mysql. Some file system won’t allow 4GB files. In that case you cant load that much big file.

    I think in your case setting max_allowed_packet property to a higher value will fix the problem.

    I think you can use following table creation script

    CREATE TABLE `image` (
        `id` INT(10) NULL DEFAULT NULL,
        `fs` LONGBLOB NULL,
        `filen` VARCHAR(50) NULL DEFAULT NULL
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using mysql database for my phonegap app but phonegap don't support php
From the Spring JDBC documentation, I know how to insert a blob using JdbcTemplate
I'm saving an image as a blob using the following, but I'm not sure
I am struggling to decide if I should be using the MySQL blob field
Is it possible to search through a MySQL database using blob data to find
Does anyone have any familiarity or experience using BITS for downloads from Azure blob
I have stored an image in a database using Blob type. Now I can
I'm using scribe for making an app that has oauth support. I didn't found
i'd like to read binary data from a blob, using the Stream interface around
I have read that using BLOB to save a path of a picture to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.