Blob Problem

Hello,
The problem that i have is that i want to insert a file residing in the network into the oracle database into a blob field and again read it from the database and show it ie either insert it into a file directly and then open it using the correct editor or open it directly. I am using java along with it but i am basically stuck on the database side.
I am sending the code which i have written till date
i basically need to know
1)the syntax i am using to interact with the database is right ie where is the error in the code
2)provided that is ok whether my overall code is on the right track.
The error message i am getting:
java.sql.exe:ORA-06550 line col22
PLS 00302: Component GETCHUNKSIZE must be declared
ORA-06550 line1 col 7
pl/sql statement ignoured
My developopment enviornment is JDeveloper3.0 as this code is having problems compiling in JDK as Jdeveloper overides a few of the jdk classes.
=========================================================================
My table structure
CREATE TABLE DOC_MAS(
DOC_MAS_SR_NO NUMBER(10),
PROJECT_NAME VARCHAR2(30),
MODULE_NO NUMBER(10),
DOC_NAME VARCHAR2(10),
DOC_TYPE VARCHAR2(10),
VERSION NUMBER(10));
CREATE SEQUENCE SEQ_DOC_MAS START WITH 1 INCREMENT BY 1;
CREATE SEQUENCE SEQ_DOC_DETAIL START WITH 1 INCREMENT BY 1;
CREATE TABLE DOC_DETAIL(
DOC_DETAIL_SR_NO NUMBER(10),
DOC_MAS_SR_NO NUMBER(10),
DATE_OF_INSERT DATE,
ACTUAL_DOC BFILE,
COMMENTS VARCHAR2(500));
===============================================================================
My connection code:
public class ConnectionParams {
// The machine on which the database resides
//public final static String s_hostName = "insn110a.in.oracle.com";
public final static String s_hostName = "192.168.1.1";
// The TNS listener port
public final static String s_portNumber = "1521";
// The database name (SID)
//public final static String s_databaseSID = "otndb";
public final static String s_databaseSID = "orcl";
// The database User ID
public final static String s_userName = "scott";
// The database user password
public final static String s_password = "tiger";
========================================================================================
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
import java.util.*;
import java.util.Date;
//import java.math.BigDecimal;
public class Sample2
Connection m_connection; //Database Connection Object
String p_doc_name=null;
String s_blobvariable = p_doc_name;
public Sample2()
dbConnection();
public static void main(String[] args)
Sample2 lobs = new Sample2();
// lobs.dbConnection();
lobs.readFileNameExt();
/*This class is for creation of connection =========================================*/
public void dbConnection() {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String l_dbConnectString =
"(DESCRIPTION=(ADDRESS=(HOST="+ConnectionParams.s_hostName+")"+
"(PROTOCOL=tcp)(PORT="+ConnectionParams.s_portNumber+"))"+
"(CONNECT_DATA=(SID="+ConnectionParams.s_databaseSID+")))";
m_connection = DriverManager.getConnection(
"jdbc:oracle:thin:@"+l_dbConnectString,
ConnectionParams.s_userName, ConnectionParams.s_password);
// m_connection.setAutoCommit(false);
System.out.println("Connection Successful");
Thread.sleep(3000);
} catch(Exception ex){ //Trap SQL errors
System.out.println("Error in Connecting to the Database "+ex.toString());
/*========================================================================================
File inserting section of the code
// THIS class gets the input from the file dialog box it gets the file path,projectName and the module no
//public void readFileNameExt(String p_doc_path,String p_module_no,String p_project_name)
public void readFileNameExt()
String p_doc_path = "c:/warea/Mehul2/TABLE5.xls";
int p_module_no = 10;
String p_project_name = "Finserve";
String p_doc_type= null;
String p_version = null;
StringTokenizer strtkn = new StringTokenizer(p_doc_path,"/");
while(strtkn.hasMoreTokens())
p_doc_name =strtkn.nextToken();
System.out.println("The file name is" +p_doc_name);
StringTokenizer strtoken = new StringTokenizer(p_doc_name,".");
while(strtoken.hasMoreTokens())
p_doc_type =strtoken.nextToken();
try{
System.out.println("The file Type is"+p_doc_type);
insertDocMas(p_doc_name,p_doc_type,p_project_name,p_module_no);
Thread.sleep(10000);
}catch (Exception e){}
}//end of method
//============================================== this class is for inserting the doc_mas details in teh table along with version checking
public void insertDocMas(String p_doc_name,String p_doc_type,String p_project_name,int p_module_no){
int p_version = -1;
int p_doc_mas_sr_no = -1;
// String verision=null;
int verision;
String s = null;
try{
Statement l_stmt = m_connection.createStatement();
ResultSet l_version_details = l_stmt.executeQuery("SELECT MAX(VERSION) FROM DOC_MAS WHERE DOC_NAME = '"+p_doc_name+"'");
if (l_version_details.next())
{ System.out.println("The Control 1");
verision = l_version_details.getInt(1);
System.out.println("The Control 2 : "+verision);
verision = verision +1;
else {
verision = 1;
System.out.println("The Control 3");
p_version = verision;
System.out.println("The value of p_version" + p_version);
l_version_details.close();
l_stmt.close();
Thread.sleep(4000);
}catch(Exception e){
System.out.println("Exception has occured at the time of insert"+e);
/* try{
Statement stmt = m_connection.createStatement();
ResultSet rset = stmt.executeQuery("select DEPTNO,DNAME,LOC from DEPT");
while(rset.next()){
BigDecimal deptno = rset.getBigDecimal(1,2);
String dname = rset.getString(2);
// Timestamp hiredate = rset.getTimestamp(3);
String loc = rset.getString(3);
System.out.println(deptno+" "+dname+" "+loc);
Thread.sleep(50000);
}catch(Exception e){System.out.println(e);}
try{
Statement l_stmt = m_connection.createStatement();
ResultSet l_seq_details = l_stmt.executeQuery("SELECT SEQ_DOC_MAS.NEXTVAL FROM DUAL");
if (l_seq_details.next())
p_doc_mas_sr_no = l_seq_details.getInt(1);
System.out.println("The Control AA");
System.out.println("The value of p_doc_mas_sr_no" + p_doc_mas_sr_no);
l_seq_details.close();
l_stmt.close();
Thread.sleep(4000);
}catch(Exception e){
System.out.println("Exception has occured at the time of selecting the current sequence number"+e);
try {
System.out.println("Creating rows in DOC_MAS.. ");
System.out.println("The Control VV");
PreparedStatement l_pstmt = m_connection.prepareStatement("insert into DOC_MAS(DOC_MAS_SR_NO,PROJECT_NAME,MODULE_NO,DOC_NAME,DOC_TYPE,VERSION) values(?,?,?,?,?,?)");//SEQ_DOC_MAS.nextval
l_pstmt.setInt(1,p_doc_mas_sr_no);//"SEQ_DOC_DETAIL.NEXTVAL"
l_pstmt.setString(2,p_project_name);
l_pstmt.setInt(3,p_module_no);
l_pstmt.setString(4,p_doc_name);
l_pstmt.setString(5,p_doc_type);
l_pstmt.setInt(6,p_version);
l_pstmt.executeUpdate(); // Execute SQL statement
l_pstmt.close();
System.out.println("The Control 3");
// Close statement
Thread.sleep(20000);
}catch(Exception e){
System.out.println("Exception has occured at the time of insert11"+e);
try{System.out.println("The Control 4");
Statement l_statement = m_connection.createStatement();
ResultSet l_doc_mas_sr_no = l_statement.executeQuery(
"SELECT max(DOC_MAS_SR_NO) FROM DOC_MAS "+
"WHERE DOC_NAME = '"+p_doc_name+"' ");//FOR UPDATE
if (l_doc_mas_sr_no.next())
p_doc_mas_sr_no = l_doc_mas_sr_no.getInt(1);
l_doc_mas_sr_no.close();
l_statement.close();
System.out.println("The Control 5");
Thread.sleep(10000);
}catch(Exception e){
System.out.println("Exception has occured at the time of insert");
loadSamples(p_doc_mas_sr_no,p_doc_name,p_doc_type);
}//Method insertDocMas() closing here
/*This class is for loading the data into the database==================================*/
public void loadSamples(int p_doc_mas_sr_no,String p_doc_name,String p_doc_type) {
int p_doc_detail_sr_no = -1;
Date p_sysdate = new Date() ;
try{
Statement l_stmt = m_connection.createStatement();
ResultSet l_seq_doc_details = l_stmt.executeQuery("SELECT SEQ_DOC_DETAIL.NEXTVAL FROM DUAL");
if (l_seq_doc_details.next())
p_doc_detail_sr_no = l_seq_doc_details.getInt(1);
System.out.println("The Control AA");
System.out.println("The value of p_doc_detail_sr_no" + p_doc_detail_sr_no);
l_seq_doc_details.close();
l_stmt.close();
Thread.sleep(4000);
}catch(Exception e){
System.out.println("Exception has occured at the time of selecting the current sequence number"+e);
try{
Statement l_st = m_connection.createStatement();
ResultSet l_date = l_st.executeQuery("SELECT sysdate FROM DUAL");
if (l_date.next())
p_sysdate = l_date.getDate(1);
System.out.println("The Control sysdate");
System.out.println("The value of p_sysdate" + p_sysdate);
l_date.close();
l_st.close();
Thread.sleep(4000);
}catch(Exception e){
System.out.println("Exception has occured at the time of selecting the sysdate"+e);
try {System.out.println("The Control 6");
System.out.println("Creating row for actual-doc in DOC_DETAILS.. ");
PreparedStatement l_pstmt = m_connection.prepareStatement("insert into DOC_DETAIL(DOC_DETAIL_SR_NO,DOC_MAS_SR_NO,DATE_OF_INSERT,ACTUAL_DOC)values(?,?,p_sysdate, empty_blob() )");
l_pstmt.setInt(1,p_doc_detail_sr_no);
l_pstmt.setInt(2,p_doc_mas_sr_no);
//l_pstmt.setDate(3,p_sysdate);
System.out.println("The Control 6AA");
l_pstmt.execute(); // Execute SQL statement
l_pstmt.close(); // Close statement
System.out.println("Created.\nLoading <map.gif> into BLOB column for doc_detail...");
System.out.println("The Control 7");
// Retrieve the row just inserted, and lock it for insertion of the
}catch(Exception e){
System.out.println("Exception has occured at the time of inserting blob locators"+e);
try {
// LOB columns.
System.out.println("The Control 7AAA");
Statement l_stmt = m_connection.createStatement();
ResultSet l_lobDetails = l_stmt.executeQuery(
"SELECT ACTUAL_DOC "+
"WHERE DOC_MAS_SR_NO = '"+p_doc_mas_sr_no+"'");
// Retrieve BLOB and CLOB streams for ACTUAL_DOC and TEXT_DOC
// columns, and load the sample files
System.out.println("The Control 8");
if (l_lobDetails.next())
// Get the BLOB locator and open output stream for the BLOB
BLOB l_mapBLOB = ((OracleResultSet)l_lobDetails).getBLOB(1);
OutputStream l_blobOutputStream = l_mapBLOB.getBinaryOutputStream();
System.out.println("The Control 9");
// Open the sample file as a stream for insertion into the BLOB column
File l_blobvariable = new File(s_blobvariable);
InputStream l_sampleFileStream=new FileInputStream(l_blobvariable);
System.out.println("The Control 10");
// Buffer to hold chunks of data to being written to the BLOB.
// In Oracle8.1.5 JDBC drivers a method getBufferSize() is available
// in the BLOB class, that returns the optimal buffer size
byte[] l_buffer = new byte[10* 1024];
System.out.println("The Control 11");
// Read a chunk of data from the sample file input stream, and write the
// chunk to the BLOB column output stream. Repeat till file has been
// fully read.
int l_nread = 0; // Number of bytes read
while ((l_nread= l_sampleFileStream.read(l_buffer)) != -1) // Read from file
l_blobOutputStream.write(l_buffer,0,l_nread); // Write to BLOB
System.out.println("The Control 12");
// Close both streams
l_sampleFileStream.close();
l_blobOutputStream.close();
System.out.println("Done Loading sample files");
System.out.println("\nRetrieving and displaying sample files..");
// Retrieve and display the LOB data just inserted
drawBLOB(l_mapBLOB,p_doc_name,p_doc_type);
//System.out.println("Done loading and displaying LOB data");
} //if statement closes here
l_lobDetails.close();// Close Result Set and statement
l_stmt.close();
} catch (Exception ex)
{ // Trap       SQL errors
System.out.println("Error loading sample files for the selected airport");
System.out.println("\n"+ex.toString());
}//Method closes here
* Retrieve the BLOB data from input BLOB column into a local file,
* and draws the image. The file type needs to be added here
public void drawBLOB(BLOB p_blob, String p_doc_name,String p_doc_type) {
//String fileType this should be passed at some point to ensure that the file gets the right extension
try {
// Open a stream to read the BLOB data
InputStream l_blobStream = p_blob.getBinaryStream();
// Open a file stream to save the BLOB data
FileOutputStream l_fileOutStream = new FileOutputStream(p_doc_name+"."+p_doc_type);
// Read from the BLOB data input stream, and write to the file output
// stream
byte[] l_buffer = new byte[10]; // buffer holding bytes to be transferred
int l_nbytes = 0; // Number of bytes read
while ((l_nbytes = l_blobStream.read(l_buffer)) != -1) // Read from BLOB stream
l_fileOutStream.write(l_buffer,0,l_nbytes); // Write to file stream
// Flush and close the streams
l_fileOutStream.flush();
l_fileOutStream.close();
l_blobStream.close();
//m_GUI.drawMap(p_doc_name,p_doc_type);
// Draw retrieved image to GUI
drawMap(p_doc_name,p_doc_type);
} catch (Exception ex) { // Trap SQL and IO errors
System.out.println("Error in retrieving and drawing map for selected airport");
System.out.println("\n"+ex.toString());
* Create a label from the image filepassed, add the label to the image area
This part will have to be modified majorly
public void drawMap(String p_doc_name,String p_doc_type) {
//Refer to SIRExtOpen.java
Runtime r = Runtime.getRuntime();
Process p = null;
if (p_doc_type.equals("html")&#0124; &#0124;p_doc_type.equals("htm"))
try{
p = r.exec( "C:\\Program Files\\Internet Explorer\\Iexplore.EXE " + p_doc_name);
//repaint();
p.waitFor();
catch(Exception ex)
ex.printStackTrace();
System.out.println(ex);
System.out.println(ex.getMessage());
if(p_doc_type.equals("txt")&#0124; &#0124; p_doc_type.equals("sql")&#0124; &#0124; p_doc_type.equals("java"))
try
p = r.exec( "C:\\WINDOWS\\notepad.EXE " + p_doc_name); p.waitFor();
catch(Exception ex)
ex.printStackTrace();
System.out.println(ex);
System.out.println(ex.getMessage());
} // end of txt , sql , java if
if(p_doc_type.equals("xls"))
try
p = r.exec( "C:\\Program Files\\Microsoft Office\\Office\\excel.EXE " + p_doc_name);p.waitFor();
catch(Exception ex)
ex.printStackTrace();
System.out.println(ex);
System.out.println(ex.getMessage());
} // end of xls if
if(p_doc_type.equals("fmb"))
try
p = r.exec( "C:\\Program Files\\Accessories\\wordpad.exe " + p_doc_name);p.waitFor();
catch(Exception ex)
ex.printStackTrace();
System.out.println(ex);
System.out.println(ex.getMessage());
} // end of fmb if
if(p_doc_type.equals("doc"))
try
p = r.exec( "C:\\Program Files\\Accessories\\wordpad.exe " + p_doc_name);p.waitFor();
catch(Exception ex)
ex.printStackTrace();
System.out.println(ex);
System.out.println(ex.getMessage());
} // end of doc if
if(p_doc_type.equals("mpp"))
try
p = r.exec( "C:\\Program Files\\Accessories\\wordpad.exe " + p_doc_name);p.waitFor();
catch(Exception ex)
ex.printStackTrace();
System.out.println(ex);
System.out.println(ex.getMessage());
} // end of mpp if
//Here you can write a statement for deleting the file in the root directory once the file is opened using any editor
}//end of method
}//This is the class closing
* This method is called when a row is selected from the combo.
* It checks if there exists data in DOC_DETAIL for the selected
* file. If there exists data, it calls drawBLOB and writeCLOB to
* display the data
/*public void fileSelected(String p_doc_mas_sr_no,String p_doc_name,String p_doc_type) {
try {
System.out.println("Retrieving LOB details for selected file..");
// Create a SQL statement
Statement l_stmt = m_connection.createStatement();
// Query DOC_DETAILS for the selected file
java.sql.ResultSet l_lobDetails = l_stmt.executeQuery(
"SELECT ACTUAL_DOC FROM DOC_DETAILS "+
"WHERE DOC_MAS_SR_NO='"+p_doc_mas_sr_no+"'");
// Check if LOB columns exist
if (l_lobDetails.next()) {
// LOB details exist
// Display airport map and suggestion book (LOB details)
drawBLOB(l_lobDetails.getBlob(1),p_doc_name,p_doc_type);
//lobs.drawBLOB(((OracleResultSet)l_lobDetails).getBLOB(1),p_doc_name,p_doc_type);
//Should this be like this
System.out.println("Done retrieving and displaying LOB details");
} else {
// No LOB details
// m_GUI.m_loadButton.setEnabled(true);
//TO BE CHECKED OUT LATER m_loadButton This is a button in the form
System.out.println("No airport map and suggestion book exist for selected airport");
System.out.println("\nPress <Load Sample2 Files> to load LOB details");
l_lobDetails.close();
l_stmt.close();
} catch (Exception ex) { // Trap SQL errors
System.out.println("Error retrieving LOB Details for the selected airport");
System.out.println(ex.toString());

You are probably better off using BLOBs rather than BFILEs. The main reason for this is that with BLOBs data integrity between file and its meta data in the database are managed and protected by the RDBMS. BFILEs are useful for legacy systems where the files already exist in some form of meaningful and managed structure that needs to be preserved.
There is a down side to BLOBs and that is performance - BLOBs are relatively slow to load into the database. However, its not too bad and the performance of extracting BLOBs out from the database is quite reasonable the bottleneck is more likely to be your LAN.
In order to use BLOBs it is important to have the right class libraries involved. For BLOBs you must use the classes12.zip (supplied with the database) for JDBC2 support and furthermore put this class high up the list of class libraries if you do not you may find that your code compiles but raises a runtime exception about invalid data types; this is because the wrong definition of the Blob class is being picked up.
Assuming that you are using BLOBs then the following describes the techniques for storing files as BLOBs in an Oracle database.
LOADING BLOBS
Assuming that you have a table with a BLOB column in it then to load a BLOB you must first create the record containing the BLOB by inserting a row into your table with the value of the BLOB column set to EMPTY_BLOB( ) (PL/SQL built in):
INSERT INTO tablex( col1, col2, colBLOB )
VALUES( val1, val2, EMPTY_BLOB() )
Then you must row lock this record and obtain the LOB locator for the BLOB just created:
stmt = connection.createStatement();
query = "SELECT colBLOB FROM tablex WHERE ... FOR UPDATE OF colBLOB";
ResultSet lockLOBSet = stmt.executeQuery(query);
At this point you should be able to use lockLOBSet.getBlob(1) to create a binary stream to load the BLOB directly into the database. Under Java Developer 2 I could never get this to work and havent tried since with Java Developer 3. Instead I used the PL/SQL DBMS_LOB package and did it using JDBC; this assumes that the file has been loaded into a buffer binaryFile and note that the maximum chunk size that dbms_lob.write can be called with is 32K:
blobLoc = lockLOBSet.getBlob(1);
while(amountWritten < fileSize)
if ((amountWritten + writeAmount) <= fileSize)
writeAmount = 32000;
else
writeAmount = fileSize - amountWritten;
System.arraycopy(binaryFile, amountWritten, buffer, 0, writeAmount);
CallableStatement cstmt =
connection.prepareCall("{call dbms_lob.write(?, ?, ?, ?)}");
cstmt.setBlob(1, blobLoc);
cstmt.setLong(2, writeAmount);
cstmt.setLong(3, amountWritten + 1);
cstmt.setBytes(4, buffer);
cstmt.execute();
cstmt.close();
amountWritten = amountWritten + writeAmount;
EXTRACTING BLOBS
Binary streams do work when it comes to reading BLOBs out of the database so things are a whole lot simpler probably worth trying it with loading BLOBs now as well.
ResultSet queryLOBSet = statement.executeQuery(query);
if(queryLOBSet.next())
lobSize = queryLOBSet.getInt(1);
blobLoc = queryLOBSet.getBlob(2);
BufferedInputStream bi;
blobBuffer = new byte[lobSize];
bi = new BufferedInputStream(blobLoc.getBinaryStream());
amountRead = bi.read(blobBuffer);
bi.close();
Regards,
Bob
null

Similar Messages

  • Blob problem (Image storing or Currupted )

    AOA!
    I am working as a developer in a companey. we made a database for HRMS. In this database there is a table EMPLOYEE with a column PICTURE of type BLOB. We were using oracle 8i initially but when we migrate to oracle 9i, we are facing a problem in image storing. The situation is, database showing ur previously stored images (those have stored in oracle 8i) but when we save a new image in that table or any other table it seams to be saved but cannot retrived. I mean when we issue a query
    SELECT EMP_ID FROM EMPLOYEE WHERE PICTURE IS NOT NULL;
    It shows the new inserted records too (thats shows us that picture has been inserted) but when we issue query from a forms6i application it didnt show any image. In case of report, when we try to query a record which newly inserted with image, it says some thing like REPORT IS UNABLE TO SHOW IMAGE FORMATE etc.
    The situation is for all table and all schema which is indicating us may be it is some thing due to oracle 9i headen technique or due to miss managment by us. we dont have DBA in our companey.
    Please help us in this regard. We will be thankfull to you.
    Usman Rana
    Dont reply to above mantioned email my actual email account is [email protected]

    hello,
    these are very specific questions about forms and reports functionality. i would suggest you publish this
    question in the forms and reports forum.
    regards,
    philipp

  • BLOB problem (image storing or image curruption)

    AOA!
    I am working as a developer in a companey. we made a database for HRMS. In this database there is a table EMPLOYEE with a column PICTURE of type BLOB. We were using oracle 8i initially but when we migrate to oracle 9i, we are facing a problem in image storing. The situation is, database showing ur previously stored images (those have stored in oracle 8i) but when we save a new image in that table or any other table it seams to be saved but cannot retrived. I mean when we issue a query
    SELECT EMP_ID FROM EMPLOYEE WHERE PICTURE IS NOT NULL;
    It shows the new inserted records too (thats shows us that picture has been inserted) but when we issue query from a forms6i application it didnt show any image. In case of report, when we try to query a record which newly inserted with image, it says some thing like REPORT IS UNABLE TO SHOW IMAGE FORMATE etc.
    The situation is for all table and all schema which is indicating us may be it is some thing due to oracle 9i headen technique or due to miss managment by us. we dont have DBA in our companey.
    Please help us in this regard. We will be thankfull to you.
    Usman Rana
    Dont reply to above mantioned email my actual email account is [email protected]

    hello,
    these are very specific questions about forms and reports functionality. i would suggest you publish this
    question in the forms and reports forum.
    regards,
    philipp

  • Blob Problem (storing Images)

    AOA!
    I am working as a developer in a companey. we made a database for HRMS. In this database there is a table EMPLOYEE with a column PICTURE of type BLOB. We were using oracle 8i initially but when we migrate to oracle 9i, we are facing a problem in image storing. The situation is, database showing ur previously stored images (those have stored in oracle 8i) but when we save a new image in that table or any other table it seams to be saved but cannot retrived. I mean when we issue a query
    SELECT EMP_ID FROM EMPLOYEE WHERE PICTURE IS NOT NULL;
    It shows the new inserted records too (thats shows us that picture has been inserted) but when we issue query from a forms6i application it didnt show any image. In case of report, when we try to query a record which newly inserted with image, it says some thing like REPORT IS UNABLE TO SHOW IMAGE FORMATE etc.
    The situation is for all table and all schema which is indicating us may be it is some thing due to oracle 9i headen technique or due to miss managment by us. we dont have DBA in our companey.
    Please help us in this regard. We will be thankfull to you.
    Usman Rana
    Dont reply to above mantioned email my actual email account is [email protected]

    I think that both your SQL is wrong and your intended use is wrong. According to the SQL reference, the following seems to be a simplified definition that seems to match what you're trying to do. UPDATE &lt;table&gt; SET &lt;column&gt; = &lt;expr&gt;. So PROPERTIES should be a &lt;table&gt; of some kind and X should be a &lt;column&gt; of that table. This changes your PreparedStatement to *"UPDATE PROPERTIES SET X = ? WHERE NAME = ?"* Then you can do ps.setBlob(1, b) and ps.setString(2, ...). Because your statement is DML you must do ps.executeUpdate(). So your code might look something like this.
    Blob b = ...;
    String x = ...;
    ps = c.prepareStatement("UPDATE PROPERTIES SET X = ? WHERE NAME = ?");
    ps.setBlob(1, b);
    ps.setString(2, x);
    int i = ps.executeUpdate();
    The executeUpdate() returns the row count (i.e. number of rows) of your DML statement. Try that and see if it helps.

  • Blob Problem (image not store or currup in database)

    AOA!
    I am working as a developer in a companey. we made a database for HRMS. In this database there is a table EMPLOYEE with a column PICTURE of type BLOB. We were using oracle 8i initially but when we migrate to oracle 9i, we are facing a problem in image storing. The situation is, database showing ur previously stored images (those have stored in oracle 8i) but when we save a new image in that table or any other table it seams to be saved but cannot retrived. I mean when we issue a query
    SELECT EMP_ID FROM EMPLOYEE WHERE PICTURE IS NOT NULL;
    It shows the new inserted records too (thats shows us that picture has been inserted) but when we issue query from a forms6i application it didnt show any image. In case of report, when we try to query a record which newly inserted with image, it says some thing like REPORT IS UNABLE TO SHOW IMAGE FORMATE etc.
    The situation is for all table and all schema which is indicating us may be it is some thing due to oracle 9i headen technique or due to miss managment by us. we dont have DBA in our companey.
    Please help us in this regard. We will be thankfull to you.
    Usman Rana

    I have a mistake , the right code is :
    <listobject:create name="mylist" columns="field,value" />
         <listobject:addrow name="mylist">
              <listobject:argument name="field" value="historyAttr1" />
              <listobject:argument name="value" value="1234" />
         </listobject:addrow>

  • BLOB problem in forms 6i

    Hi All,
    i have a problem with BLOB data type. i just create a base table block thru wizard. i have one BLOB field in my table. i use GET_FILE_NAME and READ_IMAGE_FILE to store image in base table block field and press commit. it shows 1 transaction completed. when i query record it cannot shows any record. i checked it from SQL/PLUS, it shows no record in table (select count(*) from mytable) . when i use LONG RAW type its work. i'm using ORACLE 9i database and forms 6i rel 2.
    plz tell me what i can do in this regard.
    Thanks in advance
    Shakeel

    Hello there,
    i have created a table(with 3 columns) one blob column, i commit one record as you have said and i saved it.
    (i) The sql don't display
    (ii) On forms it is showing
    (iii) i have set item property (image), if you set any other accept except image or oracle defined then it will not display.
    with best regards,
    [email protected]

  • Asp blob problem?

    Hi All,
    i upload an image from asp to blob field,but i can't display the image in asp.
    while i write an image from vb to blob ,i can display the image.
    i have read the sample code Use interMedia with OO4O and Microsoft IIS to load and retrieve rich content in InterMedia sample. the code have the same problem.
    i don't know what to do.
    help me.
    thanks

    I am using 2.2. It outputs the folowing html
    <a id="ad" href="http://portaldev.cmcinet.org/portal/server.pt/gateway/PTARGS_0_612_546_208_0_43/http%3B/portaldev.cmcinet.org/cmcportlets/adbanner/webform2.aspx">
    <img src="http://portaldev.cmcinet.org/portal/server.pt/gateway/PTARGS_0_612_546_208_0_43/http%3B/portaldev.cmcinet.org/cmcportlets/adbanner/image.jpg" alt="Community Medical Organisation" border="0" /></a>
    I believe they work different from imagebuttons. Just crate a page and add an adrotator control to it and read the images from some xml file. I can send you the code.

  • RDB BLOB problem

    Hi.
    I have problem writing blob into RDB database table via JDBC driver. I use setBinarySteam() or setBytes() method in PreparedStatement.
    If table has NOT NULL constraint on blob-field I'm trying to write JDBC driver throws exception:
    java.sql.SQLException: in <rdbjdbcsrv:execute_into>
    %RDB-E-INTEG_FAIL, violation of constraint NEW_BLOB_TABLE_NOT_NULL1 caused operation to fail
    -RDB-F-ON_DB, on database DKB1:[PRO_DB.MB_DATABASE]MB.RDB;1
    @rdb.Client.ExecuteInsert
         at oracle.rdb.jdbc.common.BasicClient.throwException(BasicClient.java:1049)
         at oracle.rdb.jdbc.common.BasicClient.throwException(BasicClient.java:1014)
         at oracle.rdb.jdbc.common.Client.ExecuteInsert(Client.java:498)
         at oracle.rdb.jdbc.rdbThin.Rdb.ExecuteInsert(Rdb.java:332)
         at oracle.rdb.jdbc.common.ResultSet.doStatement(ResultSet.java:5894)
         at oracle.rdb.jdbc.common.PreparedStatement.execute(PreparedStatement.java:1331)
         at oracle.rdb.jdbc.common.PreparedStatement.executeUpdate(PreparedStatement.java:399)
         at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
         at ru.teleform.reportgenerator.db.ReportBroker.setBinaryStream(ReportBroker.java:188)
         at ru.teleform.reportgenerator.servlets.test.doPost(test.java:18)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Thread.java:619)
    But if there is no constraint on this field everyyhing is ok. I'm using thin JDBC-driver.
    I don't know what to do.

    No, I'm not trying to set null value to this field.
    For experiment I created two similar tables. One was created with NOT NULL constraint for blob column and the other one without.
    And I execut identical insert-query on both of them. With first table query throws exception. And with second one everything is fine, query inserts correct data into this table.

  • Tomcat 4.1 Oracle Blob problem using apache commons DBCP

    Hi all,
    We are using Tomcat 4.1.12, Java 1.4.x and trying to take advantage of the connection pooling that comes with Tomcat(the apache commons DBCP).
    We are connecting to a oracle database.
    Works fine for everything EXCEPT Blobs. We have a servlet that serves images from Oracle, that works fine when it doesn't use the connection pooling, but throws an exception when we call the
    ERROR: Class:DisplayGraphic Method:processRequest(HttpServletRequest request, Ht
    tpServletResponse response)
    Exception: org.apache.commons.dbcp.DelegatingResultSet
    DataSource ds = (DataSource)ctx.lookup("jdbc/db_connection");
    Connection conn = ds.getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    pstmt = conn.prepareStatement("SELECT graphic FROM graphics WHERE graphic_id = 1");
    rs = pstmt.executeQuery();
    if(rs.next())
        oracle.sql.BLOB oBlob = ((OracleResultSet) oRS).getBLOB("GRAPHIC");
        InputStream oIS =  oBlob.getBinaryStream();
        ... etc etc...
    }Any ideas?
    Cheers,
    Alex.

    solved the problem.. i was using getBLOB instead of
    getBlob
    doh..Hi Alex,
    your problem is very interesting for me because I have a similar problem and your identical configuration...
    the instruction
    oracle.slq.BLOB aBlob = ((OracleResultSet)super.mRs).getBLOB("BLOBBONE")
    causes this:
    java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingResultSet
    To resolve this, I changed, in server.xml , the factory
    <parameter>
                        <name>factory</name>
                        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                   </parameter>
    with:
    <parameter>
    <name>factory</name>
    <value>oracle.jdbc.pool.OracleDataSourceFactory</value>
    </parameter>          
    and magically all works fine...
    But the question is... Why doesn't it work with the standard factory???
    There is a problem in the CLASSPATH that I don't see?
    Any suggestions is welcome!
    Thanks in advance!
    Giselda

  • 2.3.0b3 and PointBase Blob problem.

    The schema tool generates a BLOB with a maxsize of 1 byte in PointBase for
    fields with the "blob" extension. This is of course too small, and results
    in a "data right truncation" exception (from PointBase), when an insert is
    attempted. The column-length extension element does not affect the BLOB
    size. Is there some workaround?
    -Maciej Szefler

    I'm experiencing some additional problems with PointBase. It seems that the
    "drop" action in schema tool does not work correctly (the syntax for
    dropping the indexes is incorrect):
    $ schematool -action drop classes/com/fs/wf/impl/jdo/package.jdo
    Exception in thread "main" java.sql.SQLException: Expected to find "."
    instead f
    ound "end of SQL command" at position 41.
    at com.pointbase.dbexcp.dbexcpException.getSQLException(DashOB3242)
    at com.pointbase.jdbc.jdbcStatement.executeQuery(DashOB3242)
    at com.pointbase.jdbc.jdbcStatement.executeUpdate(DashOB3242)
    at
    com.solarmetric.kodo.impl.jdbc.datasource.StatementImpl.executeUpdate
    (Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.executeSQL(Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.dropTable(Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.dropTables(Unknown Source)
    at com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.drop(Unknown
    Source)
    at com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.main(Unknown
    Source)
    at com.solarmetric.kodo.impl.jdbc.schema.SchemaTool.main(Unknown
    Source)
    The SQL that caused this error is:
    DROP INDEX REQUESTJDOIMPL__RESPONSESXJDOX;
    DROP INDEX REQUESTJDOIMPL__RESPONSESX_REX;
    DROP TABLE REQUESTJDOIMPL__RESPONSESX;
    DROP TABLE REQUESTJDOIMPLX;
    DELETE FROM JDO_SCHEMA_METADATAX WHERE CLASSNAMEX =
    'com.fs.wf.impl.jdo.RequestJdoImpl';
    DROP INDEX RESPONSEJDOIMPL__PAYLOADXJDOIX;
    DROP TABLE RESPONSEJDOIMPL__PAYLOADX;
    DROP TABLE RESPONSEJDOIMPLX;
    DELETE FROM JDO_SCHEMA_METADATAX WHERE CLASSNAMEX =
    'com.fs.wf.impl.jdo.ResponseJdoImpl';
    This problem is not that big of a deal since dropping the tables drops the
    indexes, but the BLOB column creation issue is a big pain because I have to
    rewrite the SQL in order to increase the BLOB size.
    "Maciej Szefler" <[email protected]> wrote in message
    news:[email protected]...
    The schema tool generates a BLOB with a maxsize of 1 byte in PointBase for
    fields with the "blob" extension. This is of course too small, and results
    in a "data right truncation" exception (from PointBase), when an insert is
    attempted. The column-length extension element does not affect the BLOB
    size. Is there some workaround?
    -Maciej Szefler

  • BLOB Problems

    Hi,
    Tough problem it seems.
    I have a database with BLOB datatype and various files of various formats like pdf, office, txt.
    Most of these files blob are properly displayed using the following PHP script
    <?
    $conn = OCILogon ("","","");
    $sql = "";
    $stmt = oci_parse($conn, $sql);
    oci_execute($stmt)
    or die ("Unable to execute query");
    while ($row = oci_fetch_array($stmt)) {
    $id = $row['0'];
    $blob = $row['1'];
    $filename = $row['2'];
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename=$filename");
    echo "$blob -> readfile()";
    OCIlogoff ($conn);
    ?>
    When the display doesn't work, I have the following characters displayed.
    JAL Ø 'Oh3Â.
    Ä4á Bá Øp | €ÏðH
    # a'hÐ !
    C# ¸«ýÿ
    Ã% Ùt¾a1(TM)Læ"Y'Þq9 Nç"Ùôþ A¡Pè"Z5 Ø¥'€ b H ð /áò m@ - ÂÁÀ ª¾à X£öP 0 'P' ª9oZ%¢vk'~P ²ÞooûÕÞ l# ¤°Ü$/ fÂÃ18l^"J » ±õèÌ8Å--+æaùË<0Ý--
    The most probable problem would be the Byte Order Mark problem known from PHP http://bugs.php.net/42312 but I am not sure.
    I just don't get it. The enconding of the database is ISO. Why some documents are absolutely fine, why some are not?
    Any help would be very much appreciated.
    Edited by: user13013984 on 21 avr. 2010 13:10

    Hi
    Thanks for replying. Data storage seems fine, I have a data presentation issue. The binary cannot be read, the file format isn't recognized.
    When I try the SQL you submitted I get this :
    Erreur SQL : ORA-00932: types de données incohérents : NUMBER attendu ; BINARY obtenu
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    For example, some word documents stored as long raw work perfectly fine, some cannot be read. No txt files can be read. Some Excel files work fine, some don't.
    There are no Office versions differences between them.
    Is there any tool/code capable of reading any long raw datatype?

  • OraOLEDB provider 8.1.7.3 - BLOB problem

    Hi,
    We are using Oracle Provider OraOLEDB 8.1.6 earlier and BLOB is reading Properly...Now I upgraded the provider to OraOLEB 8.1.7.3...Now all BLOB/LONG fields are read as NULL...Same code works perfectly fine with OraOLEDB 8.1.6...
    Did we have to change any where specifically for reading BLOB in the case of OraOLEDB 8.1.7.3?
    Can anyone help since this is very urgent for my develoment work...
    Regards
    Zunil

    oh ... I forgot to say ..
    when I run query under Enterprise Manager as
    select * from Openquery (db, 'select * from table')
    then it will show me a pop-up message
    "Query Designer encountered a MS Design Tools error:
    ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]OLE DB provider 'OraOLEDB.Oracle' reported an error.
    [Microsoft][ODBC SQL server Driver][SQL Server][OLE/DB provider returned message: ORA-12545: Connect failed because target host or object does not exist]
    And I follow support.microsoft.com/support/complus/mtsandoracle.asp?SD=GN&LN=EN-US&gssnb=1,setting as follow
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDTC\MTxOCI]
    "OracleXaLib"="oraclient8.dll"
    "OracleSqlLib"="orasql8.dll"
    "OracleOciLib"="oci.dll"

  • Insert BLOB problem

    Hi:
    I'm using oracle 8.1.6 on SunOS 5.7.
    I tried to insert a MS Word file into a blob column, but failed.
    Following are what I did:
    create table test
    (id number primary key,
    text blob
    insert into test (id,text) values (1,empty_blob());
    create directory filedir as '/home/mydir';
    Declare
    lobd BLOB;
    fils BFILE;
    BEGIN
    fils := BFILENAME('filedir','test.doc');
    SELECT text INTO lobd FROM test WHERE id = 1 FOR UPDATE;
    dbms_lob.fileopen(fils, dbms_lob.file_readonly);
    dbms_lob.loadfromfile(lobd, fils, dbms_lob.getlength(fils));
    COMMIT;
    dbms_lob.fileclose(fils);
    END;
    I got error message:
    DECLARE
    ERROR at line 1:
    ORA-22285: non-existent directory or file for FILEOPEN operation
    ORA-06512: at "SYS.DBMS_LOB", line 475
    ORA-06512: at line 7
    The file test.doc is at that directory /home/mydir. I tried to replace
    'filedir' with '/home/mydir' in the line
    fils := BFILENAME('filedir','test.doc');
    but still no success.
    Could anyone give me some advices?
    Thanks,
    George

    Hi Omar,
    Could anyone tell me how to insert a file (say a word doc., or a PDF or a text document) into a column of a table of type BFILE or BLOB. I know that it is possible to map to the physical file on the filesystem thru logical directory creation. But, would like to know how to insert a file into the column and use it later for retireval, string searching, etc. from the queries. Is it thru SQL*Loader? Could u explain me(with example, if poss.) how to do this with the loader utility?
    Pls guide me thru this.
    Thanks!
    Regards,
    Sanjay

  • Zend v2 + oracle 10 + blob problem

    Hi all,
    I have a problem with display an images. Script looks like that:
    <?
    $myblobid = 1;
    $conn = oci_connect('tmp', 'tmp','db');
    $query = 'select * from photos_blob where id=:MYBLOBID';
    $stmt = oci_parse ($conn, $query);
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_execute($stmt);
    $arr = oci_fetch_assoc($stmt);
    $result = $arr['photo']->load();
    header("Content-type: image/jpeg");
    echo $result;
    oci_free_statement($stmt);
    oci_close($conn);
    ?>
    and I can not see a picture. I believe that this script works good because when I delete a "header("Content-type: image/jpeg");" i see a binary data.
    Any ideas?
    Best regards.

    You have posted your question to an inappropriate group.
    Please review the list of topics and choose more wisely. <g>

  • Byte[] serialization/deserialization BLOB problem

    I want to store an image in DB.
    I choose to store a byte[], like a BLOB (i use MySql).
    But when byte[] is serialized in DB in front of the array are inserted 27
    bytes.
    What should i do to store exact the given byte array ?
    (Or off course an ImageIcon object : for which on deserialization an
    ClassCastException is thrown).
    And which is the reason that those 27 (!?!) bytes are inserted.
    thank you in advance for your help.
    (please excuse my english)
    BytesTest.jdo
    <?xml version="1.0"?>
    <!DOCTYPE jdo SYSTEM "http://www.solarmetric.com/dtds/jdo.dtd">
    <!-- This JDO Metadata file was auto-generated on 7/2/02 3:18 PM.
    See http://www.solarmetric.com for Kodo JDO Documentation and examples. -->
    <jdo>
    <package name="jdoproject">
    <class name="BytesTest" requires-extent="true">
    <field name="bytesArray" null-value="none" primary-key="false">
    <extension key="blob" value="true" vendor-name="kodo"/>
    </field>
    </class>
    </package>
    </jdo>
    BytesTest.java
    package jdoproject;
    public class BytesTest {
    private byte[] bytesArray = null;
    public BytesTest () {
    bytesArray = new byte[30];
    for (int i = 0; i < 30; i++)
    bytesArray[i] = (byte)(65 + i);
    public String toString () {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < bytesArray.length; i++)
    sb.append(" " + (bytesArray[i] & 0xFF) + "[" +
    (char)(bytesArray[i] & 0xFF)
    + "]");
    return sb.toString();
    this must be run twice (first , to make an insertion , second to view what
    is previos inserted)
    BytesTestMain.java
    public class BytesTestMain {
    public static void main (String[] args) {
    BytesTest test = null;
    try {
    JDBCConfiguration jc = new JDBCPropertiesConfiguration();
    PersistenceManagerFactory pmf = new
    JDBCPersistenceManagerFactory(
    new FileInputStream("config/kodo.properties"));
    PersistenceManager pm = pmf.getPersistenceManager();
    Extent people = pm.getExtent(BytesTest.class, false);
    Query query = pm.newQuery(BytesTest.class, people);
    Collection result = (Collection)query.execute();
    Iterator iter = result.iterator();
    System.out.println("Found items: ");
    while (iter.hasNext()) {
    test = (BytesTest)iter.next();
    System.out.println("test= " + test);
    test = new BytesTest();
    System.out.println("Inserting item: "+test);
    Transaction t = pm.currentTransaction();
    t.begin();
    pm.makePersistent(test);
    t.commit();
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("ALL DONE---------------------");

    cross-post:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=323525

Maybe you are looking for