Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Long Raw Picture not showing in adf

user13366390Oct 22 2013 — edited Oct 22 2013

I have used following servlet to show long raw picture. the problem is in line

           Blob blob = rs.getBlob("PLAN_PIC"); 

The oracle column is Long Raw  and in ADF table this column shows as Raw. I have tried to use Raw class but could not identify proper functions. For example I used      Long blob=rs.getLong("PLAN_PIC"); it is ok but then how to get its buffered binary stream because getBinaryStream() does not work for long. I also tried to use to_blob function to convert long raw column to blob but it also gives ora-0932 error. The same table shows picture in oracle form and also Dot Net developer showed the same picture. Kindly help.

 

//servlet code is

public class imageservlet extends HttpServlet {

  

   // private static final String CONTENT_TYPE = "text/html; charset=UTF-8";   ( I checked both content types but nothing)

      private static final String CONTENT_TYPE =   "image/jpg; charset=utf-8";

    public void init(ServletConfig config) throws ServletException {

        super.init(config);

    }

    public void doGet(HttpServletRequest request,

                      HttpServletResponse response) throws ServletException,

                                                           IOException {

        response.setContentType(CONTENT_TYPE);

        String imageId = request.getParameter("id");

       // String imageId="4000";

        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/DYEDS");

            conn = ds.getConnection();

            PreparedStatement statement =

                conn.prepareStatement("SELECT plan_no, plan_pic " +

                                      "FROM tblplanpics " +

                                      "WHERE plan_no = ?");

           // statement.setInt(1, new Integer(imageId));

            statement.setString(1,imageId);

            ResultSet rs = statement.executeQuery();

            if (rs.next()) {

               Blob blob = rs.getBlob("PLAN_PIC");     

    

    

                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");

            }

        }

    }

}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 19 2013
Added on Oct 22 2013
2 comments
318 views