Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6000083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:38:34+00:00 2026-05-23T00:38:34+00:00

I’m using following code for reading images from database but when i call getter

  • 0

I’m using following code for reading images from database but when i call getter method of pb in h:datatable value to display images on jsf page i got the error “oracle.sql.BLOB cannot be cast to java.lang.String”.Any idea please?

Java class is having pb property.

Java code for reading image:

public List<ImageBean> getPb() throws Exception {
int i = 0;
List<ImageBean> pb= new ArrayList<ImageBean>(); 
String url = "jdbc:oracle:thin:@localhost:1521:globldb3";
String username = "scott";
String password = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(url, username, password);
String sql = "SELECT name,image FROM save_image";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet resultSet = pstmt.executeQuery();
while (resultSet.next()) {
 String n =resultSet.getString(1);
 File image = new File("D:\\java3.JPG");
 FileOutputStream fos = new FileOutputStream(image);
 byte[] buffer = new byte[1];
 InputStream is = resultSet.getBinaryStream(2);
 while (is.read(buffer) > 0) {
  fos.write(buffer);
 }
 pb.add(i,new ImageBean(n,resultSet.getBlob(2)));       
 i++;
 fos.close();
 }
conn.close();   
return pb;0
}  

JSF page:-

<h:dataTable  styleClass="panelGridColums" value="#{tableBean.pb}" var="i" border="1" >
<h:column>
    <f:facet name="header">Id</f:facet>
    <h:graphicImage value="#{i.pimage}" />
</h:column>
</h:dataTable>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:38:35+00:00Added an answer on May 23, 2026 at 12:38 am

    You’re making a conceptual mistake here. In HTML, images are to be represented by <img> element with a src attribute which should point to the image’s URL. This is in JSF represented by the <h:graphicImage> component whose value attribute will render the src attribute. It expects a String which in turn represents the image’s URL. It does not expect some blob, nor a byte array.

    You basically need a servlet here. You should let the image’s URL point to that servlet along with the image identifier as request parameter or pathinfo and let the servlet stream the image’s content from the DB to the response.

    E.g.

    <h:dataTable value="#{bean.images}" var="image">
        <h:column><h:graphicImage value="images/#{image.id}" /></h:column>
    </h:dataTable>
    

    where the #{image.id} returns the unique image identifier. In a servlet which is mapped on an URL pattern of /images/* you can then get it as follows

    String imageId = request.getPathInfo().substring(1);
    

    Finally use this identifier to get the content as InputStream from the DB and write it to the OutputStream of the response along a correct set of headers.

    See also:

    • How do I load an image from a DB inside a JSF page using managed beans?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.