Start New Discussion within our Software Development Community

servlet package does not exist any idea

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class EmployeeDetails extends HttpServlet{

static int i;
Connection con;
PrintWriter out;
ResultSet rs;
public void ini(){

i=0;
con=null;
out=null;
rs=null;
}
public void doGet(HttpservletRequest request, HttpServletResponse respose) throws ServletException,IOException{

i++;
out=response.getwriter();
out.println("<b>your are user no."+ i +" to visit this site.</b><br><br>");

try{
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
con.DriverManager.getConnection("jdbc:odbc:EmployeeDB","test","password");


PreparedStatement pstm=null;
String query=null;


query ="select emp_fname, address,age, desig from Employee_Master where id=?";

pstm=con.prepareStatement(query);
pstm.setInt(1,Integer.parseInt(request.getParameter("id")));
rs=pstm.executeQuery();
out.println("<b><center>Employee Details</center></b><br><br>");


ResultSetMetaData rsmd=rs.getMetaData();

int colcount=rsmd.getColunmCount();
out.println("<table align = center border=1 cellpadding=2>");

out.println("<tr>");


for (int i=1; i<=colcount;i++)
{
out.println("<th>"+rsmd.getColunmLabel(i)+"</th>");
}
out.println("</tr>");

while(rs.next()){
out.println("<tr>");
out.println("<td>"+rs.getString("emp_fname") +"</td>");
out.println("<td>"+rs.getString("address") +"</td>");
out.println("<td>"+rs.getString("age") +"</td>");
out.println("<td>"+rs.getString("desig")+"</td>");
out.println("</tr>");
}

out.println("</table>");
out.println("</body>");
}
catch(Exception e)
{
out.println(e.toString());
}
}
public void destroy(){
try{
i=0;
con.close();
out.close();
rs.close();
}
catch(SQLException se){
out.println(se.toString());
}
}
}

This article has been dead for over six months. Start a new discussion instead.