Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    2

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Why don't you use the DB2 JDBC driver?
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Sep 2009
    Posts
    2
    thk........but it too not working...

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •