Hi,
The following code is used to search a particular details from database(here database i used is Ms-access). the following code is in
servlet.. convert into jsp.. that is quite easy....
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Search extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String ename = req.getParameter("Emp_no");
int Emp_no = (new Integer(req.getParameter("Emp_no"))).intValue();
out.println(ename);
//String y = ename;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc

dbc:EMP","","");
stmt = conn.createStatement();
rs =stmt.executeQuery("select * from Emp where Empno = '" + Emp_no + "'");
out.println("<html><body ><center>");
out.println("<table border=2 width=60% bgcolor=silver>");
out.println("<tr><th width=30%>Employee Name</th><th width=15%>EmpNo</th><th width=15%>Age</th><tr>");
while(rs.next())
{
out.println("<tr><td>" +rs.getString("Name") +"</td><td>"+rs.getString("Empno")+"</td><td>"+rs.getString("Age")+"</td>");
}
out.println("<A HREF=\"/examples/jsp/Menu.jsp\">Go To MainMenu..</A>");
out.println("</table></center></body></html>");
}
catch(ClassNotFoundException e){}
catch(SQLException e){out.println(e);}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(SQLException ignored){}
}
}
}
Bye!
