Hi Clive,
 
I'm not sure if this is the best way, but it works:
 
import java.io.*;
import java.sql.*;
public class LoadBlob
{
  public static void main( String[] args )
  {
    if( args.length < 2 )
    {
      System.out.println( "Usage: LoadImage <image_file_name> <id>" );
      System.exit( 0 );
    }
    String filename = args[ 0 ];
    int albumId = Integer.parseInt( args[ 1 ] );
    Connection conn = null;
    Statement stmt = null;
    PreparedStatement ps = null;
    try
    {
      Class.forName( "org.apache.derby.jdbc.EmbeddedDriver" );
      String url = "jdbc:derby:blobDB;create=true;";
      String username = "APP";
      String password = "mypassword";
      conn = DriverManager.getConnection( url, username, password );
   }
    catch( Exception e )
    {
      e.printStackTrace();
    }
    try
    {
      stmt = conn.createStatement();
      stmt.executeUpdate("create table blob_tab (id integer, picture blob(50M))");
      ps = conn.prepareStatement(
        "INSERT INTO blob_tab (id, picture) VALUES( ?, ?)" );
      ps.setInt( 1, albumId );
      // Insert the image into the second Blob
      File image = new File( filename );
      FileInputStream fis = new FileInputStream( image );
      ps.setBinaryStream( 2, fis, ( int )image.length() );
      // Execute the INSERT
      ps.executeUpdate();
      fis.close();
      image = null;
    }
    catch( Exception e )
    {
      e.printStackTrace();
    }
    finally
    {
      try
      {
        if( ps != null ) ps.close();
        if( conn != null ) conn.close();
      }
      catch( Exception ee )
      {
        ee.printStackTrace();
      }
    }
  }
}
Susan

Clive Borrageiro <cliveb@cibecs.com> wrote:

Hi All,

 

I am trying to insert & retrieve a BLOB (an XML file) into a table that has a column of type ‘BLOB(16M)’ using Java.

 

I have tried various ways and searched the web for a solution with no luck.

 

Has anyone done this with success? If so; any help will be much appreciated.

 

Thank You

Clive