CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Java

 how to desplay image file after retrieving the image from database?

Print topic Send  topic

Author Message
shirisha19

Posts: 7
Posted: 10/25/2005, 2:42 AM

hello friends,
i have one problem in my project .it is a matrimonial site.
i have to retrieved image from database using jsp but i dont know how to display that image file at required place. if any one can help me please send reply to this forums please it's very urgent..my code is
<%@ page session="true" %>
<%@ page import ="java.sql.*"%>
<%@ page import ="java.math.*"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="java.lang.*"%>


<%
try{
out.println("Hello World!");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.println("Hello World!");
Connection con =DriverManager.getConnection("jdbc:odbc:kavitha","scott","tiger");
out.println("Hello World!");
Statement stmt=con.createStatement();
out.println("Hello World!");
String sql="select id,img from srimg where id='raju'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
//String mimeType = myContext.getMimeType(rs.getString("filename"));
//out.println(mimeType);
//response.setContentType(mimeType);
String i=rs.getString(1);
Cookie num = new Cookie("fname",i);
session.putValue("num",num);
Cookie k= (Cookie )session.getValue("num");
out.println("Num value in session is "+k.getValue());
OutputStream gb=rs.getBinaryStream(2);
FileOutputStream fos=new FileOutputStream(i+".gif");
out.println("Hello World!123");
int c;
while ((c = gb.read()) != -1)
fos.write(c);
out.println("File Written Successfully"+c);
fos.close();
String path = getRealPath(i+".gif");
out.println("Hello World!123"+path);

}
rs.close();
stmt.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
out.println("exception occured"+e);
}
String url =response.encodeURL("profile.jsp");
%>

<a href='<%=url%>'>profile.jsp</a>
View profile  Send private message
vidyasagar

Posts: 7
Posted: 11/29/2005, 1:36 AM

Hi,shirisha

Try the ServletOutputStream Interface object for display image.

and other option is using the Oracle JDBC API get the image using rs.getImage( columnname) and display in <img > tag.

Please refer the SUN site for more information

all the best.

_________________
Thank you.
vidya sagar
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.