I have a table called 'tab1'
cl_id int
cl_image image
I want to read an image from excel with the image and save it in the above table
FileInputStream fileInputStream = new FileInputStream(
"Delux.xls");
System.out.println(fileInputStream);
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
HSSFSheet worksheet = workbook.getSheet("Delux");
Iterator rows = worksheet.rowIterator();
HSSFRow row = (HSSFRow) rows.next();
List lst = workbook.getAllPictures();
Iterator it = lst.iterator();
while (rows.hasNext()) {
row = (HSSFRow) rows.next();
HSSFCell cellP1 = row.getCell((short) 1);
PictureData pict = (PictureData)it.next();
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
InputStream is = new ByteArrayInputStream(data);
try {
PreparedStatement stmt = getdbconn()
.prepareStatement(
"insert into tab1 (cl_image) values(?)");
stmt.setBinaryStream(1, is);
stmt.executeUpdate();
is.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
but when I dynamically save the image, I get an error like
"String or binary data will be truncated."
Can someone suggest me a way to achieve this?
source
share