If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > blob retrieval.....

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-09, 00:18
rockysingh399 rockysingh399 is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
blob retrieval.....

I m not able to retrieval blob data from database.....i m new user of db2.....help required......


import java.io.File;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class BlobRetrieval {

public static void main(String[] args) {
String databaseDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbURL = "jdbcdbcEEP";
String userName = "db2admin";
String password = "db2admin";
try {
Class.forName(databaseDriver).newInstance();
Connection connection =
DriverManager.getConnection(dbURL, userName, password);

PreparedStatement preparedStatement =
connection.prepareStatement(
"SELECT img FROM SAGAR.PIC WHERE ID=?");
preparedStatement.setString(1, "0738425826");
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
// materialization of the Blob
Blob blob = resultSet.getBlob(1);
InputStream inputStream = blob.getBinaryStream();
File fileOutput = new File("C:\\clonedredbookcover.jpg");
FileOutputStream fo = new FileOutputStream(fileOutput);
int c;
while ((c = inputStream.read()) != -1)
fo.write(c);
fo.close();
System.out.println("Blob retrieved");
}
// clean up

preparedStatement.close();
connection.close();

} catch (Exception e) {
e.printStackTrace();
}

}
}


Error-----unsupporedIOException
Reply With Quote
  #2 (permalink)  
Old 10-17-09, 13:03
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Why don't you use the DB2 JDBC driver?
Reply With Quote
  #3 (permalink)  
Old 10-17-09, 22:39
rockysingh399 rockysingh399 is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
thk........but it too not working...
Reply With Quote
  #4 (permalink)  
Old 10-19-09, 07:53
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I would try to look up the exact exception (I doubt it is really "unsupporedIOException"), then look at the stack trace and figure out what you did wrong there.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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 On
Pingbacks are On
Refbacks are On