473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Not able to read xlsx file saved in postgres database (as bytea) using apache POI.

9 New Member
Hi,

I am using apache POI to read a xlsx file and upload the data in the database. I have to do this work in a scheduler(at scheduled time) running on Jboss. As scheduler is running on different server from the one file was uploaded, I am using postgres bytea datatype to save the file in database using below code
Expand|Select|Wrap|Line Numbers
  1. PreparedStatement ps =
  2.                         con.prepareStatement( "UPDATE tk_tablename SET tk_filecolumnname = ? WHERE primarykey = '"
  3.                             + fileAttachment.getPrimaryKey() + "';" );
  4.                     FilePathAssociation filePathAssociation = fileAttachment.getFilePathAssociation();
  5.                     if ( filePathAssociation != null )
  6.                     {
  7.                         File blobFile = new File( filePathAssociation.getPhysicalFilePath() );
  8.                         FileInputStream fis = new FileInputStream( blobFile );
  9.                         ps.setBinaryStream( 1, fis, (int)blobFile.length() );
  10.                         ps.executeUpdate();
  11.                         ps.close();
  12.                         fis.close();
  13.                     }
  14.  
This is working fine and the file is saved in database.

But while reading the file on server using below code
Expand|Select|Wrap|Line Numbers
  1.  ResultSet rs =
  2.                         stmt.executeQuery( "SELECT tk_filecolumnname FROM tk_tablename WHERE primarykey = '"
  3.                             + fileAttachment.getPrimaryKey() + "';" );
  4.                     if ( rs != null && rs.next() )
  5.                     {
  6.                         InputStream fileInputStream = rs.getBinaryStream( 1 );
  7.                         Workbook workbook = WorkbookFactory.create( fileInputStream ); // apache POI code to read a xlsx file.
  8.                         rs.close();
  9.                         return file;
  10.                     }
  11.  
It is giving below error,
Expand|Select|Wrap|Line Numbers
  1. java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
  2.  
I know to read a xlsx file, POI needs a stream backed by OOXML. But why
Expand|Select|Wrap|Line Numbers
  1. ResultSet.getBinaryStream()
method is not returning the same input stream that was saved while creating file.

Please help or share your knowledge.

thanks,
Amit.
Sep 7 '11 #1
0 1948

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Doug | last post by:
I would appreciate a response on this. I have clients who will be placing text files information about in a network directory for example: http://www.protegen.com/clients/ Is it possible to...
1
by: Martin_Hurst | last post by:
Is it possible to establish a connection from within a postgres database to another external database on the network, i.e., not a java or scripting connection, BUT by some type of table definition...
4
by: Gerwin Philippo | last post by:
We run a postgres database (7.4) with an MsAcces(2000) frontend, and since our last upgrade from 7.2 I have the following problem: When I try to edit a record in msacces with a high recordnummer,...
4
by: comp.lang.php | last post by:
I have a very simple XML file I created as a sample: I am trying to simply read it using tree-based XML functions in PHP which I know (sorry, don't know or quickly understand DOM though that...
1
by: elena | last post by:
I have large flat file with fixed record lenght, i have to parse record and populate table with multi columns with the data, please any links or code snipets to this topic will be greatly...
2
by: bhavanirayala | last post by:
Hello All, I have XML::Parser ,installed in my server.I cant install any other modules. So I need to use only XML::Parser. Is it possible to read xml file by tag by tag using XML::Parser? If...
7
by: boss1 | last post by:
i have a text file like below: named "rez.text" and i wnt to transfer each column into oracle database which have the same column name as views here.Every time it will goto database atomatecally...
0
by: minhtran | last post by:
Hi Everyone Lately, I found the code as to read all file from Excel file as ".xls" from Excel before 2007, but does not work for ".xlsx" Excel 2007, Please, any help for me (new hired database...
0
by: user1980 | last post by:
hello.. i am developing a page in asp to open an .xlsx file and display its contents.. i have used this connection string sConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data...
3
by: chrisindfw | last post by:
I am uploading a file to a mysql database table. Now let me say that this works perfectly fine for PDF, XLS, and DOC files. However if I upload an XLSX (office 2007 file), it uploads fine, however...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.