Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.