Link to home
Start Free TrialLog in
Avatar of ws1999
ws1999

asked on

how to show blob(graphics)data from paradox by jsp

my paradox table have blob data type(graphics),how can i make it be shown in browser by jsp? (jdbc used)
Avatar of yongsing
yongsing

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>

<%
try {
    // connect to database
    Connection  connection = DriverManager.getConnection(url, userID, password);

    Statement statement = connection.createStatement();

    // retrieve image
    ResultSet resultSet = statement.executeQuery("select image from mytable where id='123'");
    if (resultSet.next()) {
        response.setContentType("image/jpg");
        BufferedInputStream inputStream = new BufferedInputStream(resultSet.getBinaryStream(1));
        OutputStream outputStream = new BufferedOutputStream(response.getOutputStream(), 1024);
        int b;
        while ((b = inputStream.read()) != -1) {
            outputStream.write(b);
        }
        inputStream.close();
        outputStream.close();
     }
    statement.close();
    connection.close();
} catch (Exception e) {}
%>
hi
i want to add few to  yongsing's comment
Jsp's are mostly used for dynamic displays though u can have the java code in them
i feel u should write a bean which will do the backend job and just returns the datat needed by jsp to display
cheers
RJ
Avatar of ws1999

ASKER

hi,yongsing,

The code i have added to my program,but there is no image showed in my browser.why

ws1999
You need to put the image in a IMG tag:

<IMG src="url">

where url is the URL to the JSP file or servlet.
Avatar of ws1999

ASKER

hi,yongsing

but the blobimage is retrieved from database,how can i specify the url
ASKER CERTIFIED SOLUTION
Avatar of yongsing
yongsing

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ws1999

ASKER

hi,yongsing,

yes, i think your suggestion will work,but another problem is when run Jsp file, there is a column not found exception,but I'm sure the column exists,and in Jbuilder's JDBC explorer I also cannot found the column which contains the Blob(graphics data type in a paradox table),I wonder where is the column?

Thanks

ws1999
Are you sure that you got the name of the column correct?
Avatar of ws1999

ASKER

yes,no problem of the name, but still it cannot be found
Use Connection.getMetaData() to get the names of the table's columns.
Avatar of ws1999

ASKER

hi,yongsing,

The problem is why the jdbc explorer of Jbuilder also can not show this blob graphics, it seems it can not explain this kind of datatype,may be i need to install some driver to support it.
Which line of your code does the problem occur? What exception is thrown? Does the column exist?
ws1999:

You have many open questions to which you must return:

https://www.experts-exchange.com/jsp/qShow.jsp?ta=msaccess&qid=20264790
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20256743
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20250343
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20249986
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20187323
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20184015
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20181707
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20180448
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20169990
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=11401958
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20230693
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20194172
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20187856
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20187852
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20187466
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20182301
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20182182
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20181487
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20181301
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20180787
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20180436
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20172201
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20153303

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

2/8
Avatar of ws1999

ASKER

i have accpeted all these answer, why always send me mail for this?????

Avatar of ws1999

ASKER

i have accpeted all these answer, why always send me mail for this?????