p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Java and JDK > Pro JSP
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 22nd, 2008, 11:02 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 12:17 PM
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 05:22 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc