I have a table in my database that contains Tiff images stored in blobs. I am trying to display these within an ADF web application. I'm running 12.1.2. It looks like the only way i can do this is by converting the tiff images to jpgs.
If i print out ImageIO.getReaderFormatNames() i dont show a tiff reader. Which makes sense that i'm getting an error java.lang.IllegalArgumentException: image == null!
From what i understand i need a java advance imaging (JAI) plugin for tiff files. I have tried including a jai jar but with no luck. Can anyone point me in the right direction.
- private void getImageFromDB2(HttpServletRequest request, OutputStream os){
- Connection conn = null;
- String id = request.getParameter("id");
- try {
-
- Context ctx = new InitialContext();
- DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/****");
- conn = ds.getConnection();
-
- PreparedStatement statement =
- conn.prepareStatement("SELECT image " + "FROM images " + "WHERE PIC_ID = ?");
- statement.setLong(1, new Long(id));
- ResultSet rs = statement.executeQuery();
- if (rs.next()) {
- Blob blob = rs.getBlob("image");
- ImageIO.write(ImageIO.read(blob.getBinaryStream()), "jpg", os);
- os.close();
- }
- } catch (Exception e) {
- System.out.println(e);
- } finally {
- try {
- if (conn != null) {
- conn.close();
- }
- } catch (SQLException sqle) {
- System.out.println("SQLException error");
- }
- }
- }