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();
while(it.hasNext())
{
temp_tablename = (String)it.next();
System.out.println("tablename - "+temp_tablename);
String sql = "select * from "+temp_tablename;
try{
rs = st.executeQuery(sql);
while(rs.next())
{
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)
{
System.out.println(e.getMessage());
}
temp.add(MemberDet);
}
return temp;
}
Here is the code:(for inserting to the oracle db)
public void vInsertPhoto(String product,String memberno,String polserno,String memsince,InputStream picture)
{
PreparedStatement st1 = null;
String sql = "insert into APP_MEMBER_PHOTO_DETAILS (AMP_PRODUCT_CODE,AMP_MEMBER_NO,AMP_MEM_REFERENCE_NO,AMP_MEMBER_PHOTO) values(?,?,?,?)";
try{
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);
st1.executeUpdate();
System.out.println("Insertion is happened");
}
else
System.out.println("picture is null");
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
finally
{
try {
st1.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Please help me out to solve this problem