Program 2
package model;
public class Student
{
private int rno;
private String name;
private int phy;
private int math;
private int chem;
public int getRno() {
return rno;
}
public void setRno(int rno) {
this.rno = rno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPhy() {
return phy;
}
public void setPhy(int phy) {
this.phy = phy;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getChem() {
return chem;
}
public void setChem(int chem) {
this.chem = chem;
}
}
Program 3
package mycon;
import java.sql.*;
public class Myconnection
{
//Driver Load
static
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver load");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
}
//Connection method
public static Connection getConnection()
{
Connection con=null;
try
{
con=DriverManager.getConnection("jdbc:mysql:/dataflair", "root", "root@data");
System.out.println("Database Connected....");
return con;
}
catch(SQLException e)
{
System.out.println(e);
}
return con;
}
}
Program 4
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package view;
import dao.StudentDAO;
import java.sql.Connection;
import model.Student;
/**
*
* @author admin
*/
public class TestMain
{
public static void main(String[] args)
{
Student S=new Student();
S.setRno(101);
S.setName("Vivek");
S.setPhy(90);
S.setChem(80);
S.setMath(99);
StudentDAO sd=new StudentDAO();
if(sd.insertStudent(S))
System.out.println("Record inserted......");
}
}
Program 6
package controller;
import dao.StudentDAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Student;
/**
*
* @author admin
*/
public class InsertData extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
{
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet InsertData</title>");
out.println("</head>");
out.println("<body>");
int srno,sphy,schem,smath;
String sname;
srno=Integer.parseInt(request.getParameter("txtRno"));
sname=request.getParameter("txtName");
sphy=Integer.parseInt(request.getParameter("txtPhy"));
schem=Integer.parseInt(request.getParameter("txtChem"));
smath=Integer.parseInt(request.getParameter("txtMath"));
Student S=new Student();
S.setRno(srno);
S.setName(sname);
S.setPhy(sphy);
S.setChem(schem);
S.setMath(smath);
StudentDAO sd=new StudentDAO();
if(sd.insertStudent(S))
out.println("<font color=green size=5>..................Record Inserted Succefully..............");
out.println("</body>");
out.println("</html>");
}
catch(Exception e)
{
out.println(e);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}