Advertisement

03.05.2008 at 09:38AM PST, ID: 23216806
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Inserting and exporting files from PostgreSQL

Tags: Java
Hello,

I'm creating a web-app in Netbeans using Tomcat/JSP (with CachedRowSets for manipulating data) and the PostgreSQL database. So, I want to to create a page where I import some data in a specific table of the database and then export them during a query in another page. I also want to store an image in the database and after googling a little I found that you can do that in PostgreSQL using the bytea datatype. So the code goes as following:

 CachedRowSet crs = PDFInsertProvider.getCachedRowSet();
        try {
            crs.execute();  // unless it's already been executed.
            crs.moveToInsertRow();
            crs.updateInt("titlesid", new Integer(32423));
            crs.updateString("titles", getTextField1().getText().toString());
            UploadedFile file2 = getFileUpload2().getUploadedFile();
            UploadedFile file1 = getFileUpload2().getUploadedFile();
               
            crs.setBinaryStream(3, file2.getInputStream(), file2.getInputStream().available());
            crs.setBinaryStream(4, file1.getInputStream(), file1.getInputStream().available());
} catch (Exception e) {e.printStackTrace()}
            crs.insertRow();
            crs.moveToCurrentRow();
            crs.acceptChanges();
            info("Row Inserted via CachedRowSet");
            crs.release(); // release rowset memory

where UploadedFile -> org.apache.myfaces.custom.fileupload. So rows 3, 4 in the database are bytea datatype. This executes normally with a message: Row Inserted via CachedRowSet.

First question: If I psql to 'postgres' and do a 'select * from files' (where files is the table's name) . Then I can see the data for the first two columns but not for the last two.. Is this correct? Should the DOS prompt display them?

The code for retrieving the object goes as following:

            ResultSet set = deliveryBooksProvider.getCachedRowSet().getOriginal();
            set.first();
            InputStream stream1 = set.getBinaryStream("thumbimage");
            InputStream stream2 = set.getBinaryStream("pdffile");

where deliveryBooksProvider is of CachedRowSetDataProvider class. But stream1, stream2 result in null.

Any ideas?
Start your free trial to view this solution
Question Stats
Zone: Database
Question Asked By: deathstar641
Solution Provided By: adrpo
Participating Experts: 1
Solution Grade: A
Views: 8
Translate:
Loading Advertisement...
03.08.2008 at 11:28AM PST, ID: 21078269

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628