As we note, it is easy to move-in a photograph of other LOB image, by storing
an empty BLOB table column, and then re-selecting it FOR UPDATE, streaming the
image into the BLOB column, and then storing it with a COMMIT.
Below is some psuedocode to save an image from a PC client onto a pictures
table in Oracle, with the image table having only a primary key and a blob
column. If you don't want to write your own BLOB loading program, you can
hire experts to create a custom program to capture and upload images from a
client PC into an Oracle table, just contact us at .
public boolean saveImageToDatabase(Image
image, int pri_key)
{
if (!createEmptyBlobRow(pri_key)) return false;
BLOB tempBlob = getTempBlob(pri_key);
if (tempBlob == null) return false;
if (!writeBlobToDatebase(tempBlob)) return false;
return true;
}
private boolean createEmptyBlobRow(int pKey)
{
try
{
stat.executeUpdate("insert into x_pictures" +
call BC for complete script
" ( " + pKey + "," + EMPTY_BLOB()");
return true;
}
catch (SQLException e)
{
e.printStackTrace();
parm.logFile(e.toString());
}
return false;
}
private BLOB getTempBlob(int pKey)
{
try
{
rs = stat.executeQuery("select blob_content from x_pictures" +
call BC for complete script
if (rs.next()) return ((OracleResultSet) rs).getBLOB("blob_content");
}
catch (SQLException e)
{
e.printStackTrace();
parm.logFile(e.toString());
}
return null;
}
private boolean writeBlobToDatebase(BLOB t_Blob)
{
try
{
int chunksize = t_Blob.getChunkSize();
byte[] byteBuffer = new byte[chunksize];
call BC for complete script
long position = 1;
int bytesRead;
while ((bytesRead = b_in.read(byteBuffer)) != -1)
{
t_Blob.putBytes(position,byteBuffer);
position += bytesRead;
}
stat.execute("COMMIT");
return true;
}
catch (SQLException e)
{
e.printStackTrace();
parm.logFile(e.toString());
return false;
}
catch (FileNotFoundException e)
{
e.printStackTrace();
parm.logFile(e.toString());
return false;
}
catch (IOException e)
{
e.printStackTrace();
parm.logFile(e.toString());
return false;
}
}
}
Cosimo shares this example of using Coldfusion code that uses java to
send a stream as a parameter to a stored procedure to store a Oracle
BLOB. It is capable of loading a record of several fields
including a CLOB in 1 call to the database. So I created a stored
procedure :
create or replace PROCEDURE ADD_TEST_bLOB
( blobid IN VARCHAR2
, blobdata IN BLOB
) AS
begin
INSERT INTO test_blob_table values(blobid,
blobdata);
COMMIT;
END ADD_TEST_BLOB;
and I call it from this coldfusion code :
<!---this handles a binary file for a blob--->
<!---build the
db connection--->
<cfset factory = createobject("java","coldfusion.server.ServiceFactory")>
<cfset dsService = factory.getDataSourceService()>
<cfset ds =
dsService.getDatasource( "DataSource1" )><!---this is the named
datasource from the cf server--->
<cfset con = ds.getConnection()><!---This
is the database connection for java objects to use.--->
<!---get the file and read it into a variable--->
<cfhttp url="http://server.com/test2.pdf"
getAsBinary="yes" result="myfile"></cfhttp>
<!---create the
stream for the blob--->
<cfset bytestreamobj = createobject("java","java.io.ByteArrayInputStream")>
<cfset bytestream = bytestreamobj.init(myfile.filecontent)>
<!---create the callable statement--->
<cfset cs =
con.prepareCall("begin db.add_test_blob(?,?); end;")>
<!---assign the parameters and execute the statement--->
<cfscript>
cs.setObject("blobid","id");
cs.setBinaryStream("blobdata",bytestream,len(myfile.filecontent));
cs.execute();
</cfscript>