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 8851299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:07:18+00:00 2026-06-14T13:07:18+00:00

I use Glassfish 3.1.2.2, Sql Server 2005, PF 3.4 and Mojarra 2.1.6. Ide Eclipse

  • 0

I use Glassfish 3.1.2.2, Sql Server 2005, PF 3.4 and Mojarra 2.1.6. Ide Eclipse Juno.

I use stored procedure, and add jar commons-io.1.4 and commons-fileupload.1.2.1

In database, we save all file (pdf, doc, xls, etc.) in varbinary.
I have these doubts:

  1. How I can upload any file (pdf, doc, xls, etc.) with p:fileupload and save as varbinary file in the database?
  2. How I can download any varbinary file of database with p:FileDownload?
  3. How I can show pdf with p:media, recovering files varbinary from the database?

ONE QUESTION

How I can upload any file (pdf, doc, xls, etc.) with p: fileupload and save them to the database?

I undestood the p:fileupload, since documentation.
I use this method, handlerFileUpload, for upload a file. Firsts get the inputScream of the event

<p:fileUpload fileUploadListener="#{fileBean.handleFileUpload}" />

public class FileBean {
    public void handleFileUpload(FileUploadEvent event) {
       UploadedFile file = event.getFile();
       //application code
    }
}

I used file.getInputStream and sent the stored procedure a BinaryStream
setBinaryStream(4, inputStream, (int)inputStream.toString().getBytes().length);

This is good??

TWO QUESTION

How I can download any varbinary file with p:FileDownload?

I recover a varbinary since database with getBytes.
Remember I use the stored procedure.

This method is in a class with request scope.

   public byte[] ArchivoBin(int CDTPEnlaceImagen, int iddoc) {
  Context();
  Null_Rs_and_Proc();
  Connection(0);
  PA(2, 51);

  [b]byte[] file = null;[/b]

  try {
     setProc(getCon().prepareCall(getCall()));
     getProc().setInt(1, CDTPEnlaceImagen);
     getProc().setInt(2, iddoc);

     setRs(getProc().executeQuery());
     getRs().next();

     [b]file = getRs().getBytes(1);[/b]
     System.out.println(file);
  }
  catch(SQLException e) {
     System.out.println("Exception ArchivoBin");
     System.out.println(e);
  }
  CloseConnections();

  return file;}

But, when i get the file in bytes, i convert a bytes to inputscream, and then inputscream to DefaultStreamedContent.

This part is a class with request scope.

byte[] bytes = null;
bytes = getRecuperarDatos().ArchivoBin(
               1, 
               idarchivo);

//Archivo is a Session Scope
getArchivo().setFile(new DefaultStreamedContent(
                  [b]new ByteArrayInputStream(bytes)[/b], 
                  "application/pdf", 
                  nomArchivo));

The f:download not get the file correct, It is corrupt.

<h:commandButton value="Download">
           [b]<p:fileDownload value="#{archivo.file}"[/b] />
        </h:commandButton>

I don’t know why this bad

THREE QUESTION

How I can show pdf with p:media, recovering varbinary files from the database?

This is similar to TWO QUESTION, p:media say
“An error has occurred while loading the PDF document”

  • 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-14T13:07:19+00:00Added an answer on June 14, 2026 at 1:07 pm

    All is solved, when i save the file in database with the method contents.
    Specifically, with

    public void SubirAlBaseDatos(FileUploadEvent e) {
      bytes[] file = e.getFile().getContents();
    
    );
    

    thus, I can show in p:media, and donwload in p:filedownload.
    Something insignificant was causing the problem.

    Thank!! BalusC for your tips
    source

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

Sidebar

Related Questions

I am attempting to add an Interbase connection pool to GlassFish v3 to use
I make use of: NetBeans IDE 6.7.1, GlassFish v2.1, Oracle 10g XE, JAVA 6
I develop a Webservice using Netbeans 6.9 and I use an embedded glassfish server
i have an spring web application (on glassfish server) that use JDBC connection pool.
At the moment we use glassfish 3.1 as application server for our enterprise application.
I want to do get data from sql server database so I use to
I want use glassfish as the solr search server, but I don't know how
I use Glassfish server 3.1.1, and I successfully configured my realm for the usergroups.
First of all: I use GlassFish 3.1 + Eclipse Java EE indigo. I want
I'm attempting to use hibernate entity manager with mysql and glassfish. I'm getting the

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.