Hi,
I am going to insert/retrieve image in database
table:
create table MyPictures (
id INT PRIMARY KEY,
name VARCHAR(11),
myphoto BLOB
)
my
java class
public class InsertPictureToOracle {
public static void main(
String[] args) throws Exception, IOException, SQLException {
Connection conn = null;
DBUtils.loadDriver();
conn = DBUtils.fetchConnection();
FileInputStream fis = null;
PreparedStatement ps = null;
Statement stmt = null;
String INSERT_PICTURE = "insert into MyPictures(id, name, myphoto) values (?, ?, ?)";
System.out.println("i am here");
try {
conn.setAutoCommit(false);
File file = new File("com/cisco/wipro/dca/GAJANANBABA.jpg");
fis = new FileInputStream(file);
ps = conn.prepareStatement(INSERT_PICTURE);
ps.setString(1, "001");
ps.setString(2, "psm");
ps.setBinaryStream(3, fis, (int) file.length());
System.out.println("i am there");
ps.executeUpdate();
conn.commit();
System.out.println("insert image successfully");
ResultSet rs =stmt.executeQuery("select myphoto from MyPictures where id=001");
byte[] imgbytes=null;
if(rs.next()) {
imgbytes=rs.getBytes(1);
}
rs.close();
System.out.println("populate image successfully");
} catch(Exception SQLexp){
SQLexp.printStackTrace();
System.out.println("Exception while interacting with the database " + SQLexp);
} finally {
DBUtils.closeConnection(conn);
try {
stmt.close();
} catch(Exception e) {
e.printStackTrace();
}
}
i am getting following error:
ORA-01460: unimplemented or unreasonable conversion requested
please help