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>
|
|
|
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 |
|
|
|