umer abid - 2020-02-24

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

public class firstServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
    res.setContentType("text/html");
  PrintWriter out = res.getWriter();
  String title = "Database Result";

try{
    // Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    Connection con;
    Statement stm;
    ResultSet rs;


    con= DriverManager.getConnection("jdbc:ucanaccess://E:/mscit18m/student.accdb");
    stm= con.createStatement();
    rs=stm.executeQuery("SELECT * FROM student_info");
    out.println("Id    Name      Roll num");
    while(rs.next()){
        String str1=rs.getString(1);
        String str2=rs.getString(2);
        String str3=rs.getString(3);


        HttpSession session = req.getSession();
    String str=session.getAttribute("key").toString();

    out.println(str1);
    out.println(str2);
    out.print(str3);
    rs.close();
    stm.close();
    con.close();
}


}catch(Exception e){
    System.out.println(e.toString() + "<br>");

    System.out.println("Database Connected.");


}

}
}