JDBC - Servlet connectivity

SERVLET - JDBC

Stud.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="magenta" text="blue">
<h1>   Student mark list </h1>
<form method ="get"  action = "stud"> <br>
NAME :     <input type= "text" NAME = "nam" > <br> <br>
ROLL NO: <input type= "text" NAME = "rno"> <br> <br>
MARK1 :  <input type= "text"  NAME = "m1" > <br> <br>
MARK2 :  <input type= "text"  NAME = "m2" > <br> <br>
MARK 3 :  <input type= "text"  NAME = "m3" > <br> <br>
<input type= "submit" value = "submit" ><br > <br> <br>
</form>
</body>
</html>

Stud.java

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

/**
 * Servlet implementation class Stud
 */
@WebServlet("/Stud")
public class Stud extends HttpServlet {
       private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Stud() {
        super();
        // TODO Auto-generated constructor stub
    }

       /**
        * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
        */
    int m11,m22,m33,tot,avg;
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    {
    res.setContentType("text/plain");
    PrintWriter out=res.getWriter();
    String a = req.getParameter("nam");
    String b = req.getParameter("rno");
    String m1=req.getParameter("m1");
    String m2=req.getParameter("m2");
    String m3=req.getParameter("m3");
    try{
    m11=Integer.parseInt(m1);
    m22=Integer.parseInt(m1);
    m33=Integer.parseInt(m1);
    }
    catch(Exception e)
    {
    }
    tot=m11+m22+m33;
    avg=tot/3;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    try
    {
    Connection c = DriverManager.getConnection("jdbc:odbc:Marklist","","");
    Statement s=c.createStatement();
    s.executeUpdate("insert into marktable values('"+a+"',"+b+","+m1+","+m2+","+m3+","+tot+","+avg+")");
    s.close();
    c.close();
    }
    catch(Exception e)
    {
    }
    out.println("<html> <body bgcolor=aqua text=red>");
    out.println("<h1 align=center>STUDENT DETAILS </br>");
    out.println("NAME:" +a);
    out.println("<br> Roll No:" +b);
    out.println("<br> TOTAL: " +tot);
    out.println("<br> AVERAGE:" +avg);
    out.println("</h1></body></html>");
       }

       /**
        * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
        */
       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              // TODO Auto-generated method stub
       }
}


Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number