
I have list of files in my database. I want to display these files in browser according to the input. My need is like google search result. when i click on the link it should display that corresponding file from database. I have list of file id related to search. I want to retrieve and display all the file using list of file ID. Is there is any other way? Please help. Thanks in advance.

1)fileid.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<HTML>
<table >
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement stmt=con.createStatement();
String strQuery = "select * from file";
ResultSet rs = stmt.executeQuery(strQuery);
while(rs.next()){
%>
<tr>
<td>
<a href="displayfile.jsp?fileid=<%=rs.getInt(1)%>">
<%=rs.getInt("id")%></td>
</tr>
<%
}
rs.close();
con.close();
stmt.close();
}
catch(Exception e)
{
e.getMessage();
}
%>
</table>
</HTML>
2)displayfile.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<%
int id = Integer.parseInt(request.getParameter("fileid"));
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
String strQuery = "select file_data from file where id="+id;
ResultSet rs = st.executeQuery(strQuery);
String fileLen="";
if(rs.next()){
fileLen = rs.getString(1);
}
rs = st.executeQuery(strQuery);
if(rs.next()){
int len = fileLen.length();
byte [] rb = new byte[len];
InputStream is = rs.getBinaryStream(1);
int index=is.read(rb, 0, len);
st.close();
response.reset();
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}
catch (Exception e){
e.printStackTrace();
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.