Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 22nd, 2008, 10:02 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default BLOB: file is empty after retrieving blob data thr

I am trying to insert blob data through JDBC. Then i am retrieving it and writing it as a file. After writing the file when I am opening it it is corrupted.

Here is my code...


 
Quote:
quote:package com.satyam.dashboard.business;
Quote:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.satyam.spring.DatabaseConnection;



public class ConnectDatabase {

    public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException{


        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@bbf-vsr004.corp.satyam.ad:1521:SATORA","dash_dev","dev 007");

        PreparedStatement pstmt = conn.prepareStatement("insert into DASH_FILE_STORAGE values (?,?,?)");
        pstmt.setInt(1,300);
        pstmt.setString(2, "DASH_SOW_MASTER");
        File fBlob = new File ( "C:\\Documents and Settings\\td41834\\Desktop\\Dashboard.doc" );
        FileInputStream is = new FileInputStream ( fBlob );
        pstmt.setBinaryStream (3, is, (int) fBlob.length() );
        pstmt.execute ();

        System.out.println("after execute");

        Statement stmt = conn.createStatement ();
        ResultSet rs= stmt.executeQuery("SELECT * FROM DASH_FILE_STORAGE");
        while(rs.next()) {
        int val1 = rs.getInt(1);
        String val2 = rs.getString(2);
        InputStream val3 = rs.getBinaryStream(3);
        OutputStream os = new FileOutputStream("D:/blob/Dashboard.doc");
        while(true){
            int b = val3.read();
            if(b<0)
                break;
            os.write(b);
        }
        val3.close();
        os.close();
        System.out.println(" has been copied.");

        } rs.close();


            }



}
Regards
__________________
Regards
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Blob data jingo BOOK: Beginning VB.NET Databases 0 January 2nd, 2006 04:48 AM
Empty Text or blob field ODBC Drivers (0x8002009) MaBel Classic ASP Databases 1 May 6th, 2005 11:17 AM
Problem inserting blob data/uploading file - MySQL kyle_shea Beginning PHP 2 February 15th, 2005 10:18 AM
inserting blob data into database taoufik Beginning PHP 2 November 19th, 2004 09:28 AM
BLOB field file types kend SQL Server ASP 0 December 19th, 2003 02:45 PM



All times are GMT -4. The time now is 08:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.