Display images in Carousel item

813 views Asked by At

I'm working with ADF and need to display images in a Carousel. Have written the following code in servlet, but on page load it assign the value "weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB@xxx " (xxx - some alpha numeric value) to the blob object if an image exists in the database for that particular record fetched

Link referred - http://www.baigzeeshan.com/2010/10/display-images-in-carousel-item-in.html

public void doGet(HttpServletRequest request,
                  HttpServletResponse response) throws ServletException,
                                                       IOException {
    response.setContentType(CONTENT_TYPE);
    String imageId = request.getParameter("id");
    OutputStream os = response.getOutputStream();
    Connection conn = null;
    try {
        Context ctx = new InitialContext();
        //Datasource as defined in <res-ref-name> element of weblogic.xml
        DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/HrXEDS");
        conn = ds.getConnection();
        PreparedStatement statement =
            conn.prepareStatement("SELECT image_id, image_blob " +
                                  "FROM hr_image_table " +
                                  "WHERE image_id = ?");
        statement.setInt(1, new Integer(imageId));
        ResultSet rs = statement.executeQuery();
        if (rs.next()) {
            Blob blob = rs.getBlob("IMAGE_BLOB");
            System.out.println("-- blob --" + blob);
            BufferedInputStream in =
                new BufferedInputStream(blob.getBinaryStream());
            int b;
            byte[] buffer = new byte[10240];
            while ((b = in.read(buffer, 0, 10240)) != -1) {
                os.write(buffer, 0, b);
            }
            os.close();
        }
    } catch (Exception e) {
        System.out.println(e);
    } finally {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException sqle) {
            System.out.println("SQLException error");
        }
    }
}
1

There are 1 answers

0
Rafael Guillen On

You could have a problem if you are using a datasource and the configuration in Weblogic Server is wrapping the data types.

Open the Weblogic Server Administration Console (server:port/console) in a browser

Go to Services -> Data Sources -> YourDataSource -> Connection Poll -> Advanced

Uncheck the property Wrap Data Types.

Hope it helps...