This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Oracle/OAS and the fly likes Inserting Blob data into Oracle DB through JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Inserting Blob data into Oracle DB through JDBC" Watch "Inserting Blob data into Oracle DB through JDBC" New topic

Inserting Blob data into Oracle DB through JDBC

Mythily Mr

Joined: Jul 19, 2011
Posts: 4
Hello friends,

I need to insert an image into the oracle db using jdbc.
I'm extracting the image from access db first as getBinaryStream and then inserting the same into oracle Blob data type column.

In access the image is stored in a column with data type OLE Object.

When i did this am geeting an error like

Io exception: InputStream is no longer valid - the Statement has been closed, or the cursor has been moved

Here is the code(for extracting data from Access Db)
public ArrayList<ArrayList<Member>> vSelectAll(ArrayList<String> tablename)
ArrayList<ArrayList<Member>> temp = new ArrayList<ArrayList<Member>>();
String temp_tablename =null;
Iterator it = tablename.iterator();
temp_tablename = (String);
System.out.println("tablename - "+temp_tablename);

String sql = "select * from "+temp_tablename;
rs = st.executeQuery(sql);
product = rs.getString("PRODUCT");
Integer uwyear1 = rs.getInt("POLYEAR");
uwyear = uwyear1.toString();
memberno = rs.getString("MEMNO");
polserno = rs.getString("POLSRL");
Integer memsince1 = rs.getInt("MEMSINCE");
memsince = memsince1.toString();
picture = rs.getBinaryStream("PICTURE");

MemberDet.add(new Member(product,uwyear,memberno,polserno,memsince,picture));
System.out.println("MemberDet - "+MemberDet.size());
catch(SQLException e)
return temp;
Here is the codefor inserting to the oracle db)

public void vInsertPhoto(String product,String memberno,String polserno,String memsince,InputStream picture)
PreparedStatement st1 = null;

st1 = con.prepareStatement(sql);
if(picture !=null)
st1.setString(1, product);
st1.setString(2, memberno);
st1.setString(3, polserno);
st1.setBinaryStream(4, picture,1);
st1.setString(5, memsince);
System.out.println("Insertion is happened");
System.out.println("picture is null");
catch(SQLException e)
try {

} catch (SQLException e) {
// TODO Auto-generated catch block

Please help me out to solve this problem
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
Hi Mythily,

You can not just store blob pointer inputstream in memory. Either you should fetch all the bytes and store it in memory in order to use it in vInsertPhoto method (not good), or you should read some bytes and then write it immediately.

You have to merge your methods into one method that will read one row from Access DB then insert it to Oracle DB.

I agree. Here's the link:
subject: Inserting Blob data into Oracle DB through JDBC
jQuery in Action, 3rd edition