我试图将图片插入数据库,并自动递增photo_id。
我的表列如下:
PHOTO_ID (primary key),
USERNAME (fkey),
PICTURE,
PICTURE_TITLE,
LIKES
我的代码是
public class UploadPhotoDao {
public int insertPhoto(UploadPhotoBean uploadBean){
Connection con = null;
PreparedStatement ps = null;
int index = 0;
final String query = "INSERT INTO PHOTOS_DETAILS (PHOTO_ID,USERNAME,PICTURE,PICTURE_TITLE,LIKES) VALUES (PHOTO_ID_SEQUENCE.nextval,?,?,?,?)";
try {
con = ConnectionUtil.getConnection();
ps = con.prepareStatement(query);
ps.setString(1, uploadBean.getUsername());
File file =new File(uploadBean.getPicture());
FileInputStream fis = new FileInputStream(file);
ps.setBinaryStream(2, fis, fis.available());
ps.setString(3, uploadBean.getPictureTitle());
ps.setInt(4, new Integer(0));
index = ps.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
ConnectionUtil.closeQuitly(ps);
ConnectionUtil.closeQuitly(con);
}
return index;
}
}
我得到的错误:
java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested