For the code below, i googled lots, but somehow i couldn't figure out the error.. with respect to "img src" tag.
There might be silly mistake, but it would be great if someone could help me out.
I have saved my images inside the image folder, which is placed inside the project folder...
the database has the image url under "image" attribute... so i am trying to retrieve the url from the database through <%=rs.getString("image") %>
is that correct ?
<html>
<body>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.mysql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page language="java"%>
<%@ page session="true"%>
<%@ page import="java.sql.*"%>
<%
Blob image = null;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String iurl1=null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:portnumber/dbname","","");
stmt = con.createStatement();
rs = stmt.executeQuery("select * from tablename where id = 1");
}
catch (Exception e) {
out.println("DB problem");
return;
}
finally {
try {
rs.close();
stmt.close();
con.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
%>
<table border="2">
<tr><th>DISPLAYING IMAGE</th></tr>
<tr><td>Image 2</td></tr>
<tr>
<td>
<img src="<%=rs.getString("image") %>" width="500" height="500"/>
</td>
</tr>
</table>
</body>
</html>