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

  • SEARCH
  • Home
  • 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 8909889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:32:58+00:00 2026-06-15T03:32:58+00:00

I am using JSF2.0, jetty server and Postgres database. I want to store mp3

  • 0

I am using JSF2.0, jetty server and Postgres database. I want to store mp3 file in database in byte array formet. I upload the byte array of mp3 file. But when I retrive same byte array from database I get byte array of double size and my because of that my mp3 file is not working as well.

public void updateAnnouncementDetail(AnnouncementDetail announcementDetail) {
    System.out.println("Upload  byte array size:" + announcementDetail.getContent().length);
    Session sess=get Session();
    sess.beginTransaction();
    sess.save(announcementDetail);
    sess.getTransaction().commit();
    AnnouncementDetail detail;
    detail = retrieveAnnouncementDetailById(new AnnouncementDetailPK(announcementDetail.getAnnouncementDetailPK().getAnnouncement(), announcementDetail.getAnnouncementDetailPK().getLanguage()));
    System.out.println("Retrived byte array size:" + detail.getContent().length);
}

Output:

Upload byte array size:384440

Retrived byte array size:768879

I dont know why it is happening. I am storing byte array and on the next line I am retriving it. But I get byte array of double size. Let me know if you need more details.

  • 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-15T03:32:59+00:00Added an answer on June 15, 2026 at 3:32 am

    When dealing with binary data in Postgres, it is important to use proper data binding.

    First, data column must be of type BYTEA. Is that the case?

    To store data, use prepared statements and be sure to call setBinaryStream():

    File file = new File("myimage.gif");
    FileInputStream fis = new FileInputStream(file);
    PreparedStatement ps = conn.prepareStatement(
        "INSERT INTO images VALUES (?, ?)"
    );
    ps.setString(1, file.getName());
    ps.setBinaryStream(2, fis, (int)file.length());
    ps.executeUpdate();
    ps.close();
    fis.close();
    

    To retrieve data, also use prepared statements and use getBytes():

    PreparedStatement ps = conn.prepareStatement(
        "SELECT img FROM images WHERE imgname = ?"
    );
    ps.setString(1, "myimage.gif");
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        byte[] imgBytes = rs.getBytes(1);
        // use the data in some way here
    }
    rs.close();
    ps.close();
    

    See more here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JSF2 with Pure JPA2. But the problem is with entityManager, @PersistenceContext
i want to use jQuery to sync values of JSF2 components. We are using
I am using JSF2 with Prime faces. I will want to show all the
I have using jsf2.0 in eclipse ide.I have a problem to store a image
Im working on a web application using JSF2 . I want to pass parameters
I am using JSF2.0/primefaces I want to create a validator, the validator should validate
I am using JSF2.0 and Glassfish v3. I have a ValidatorMessage.properties file under WEB-INF>Classes
Using jsf2 (see maven dependencies ) <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.1.10</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId>
I am using jsf2.0 with primefaces.My application was working fine with all browsers includes
I have a web app. I am using JSF2 framework. My problem started when

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.