Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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.
- */
- import com.mysql.jdbc.Connection;
- import java.io.*;
- import java.io.PrintWriter;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.servlet.ServletException;
- import javax.servlet.http.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- *
- * @author 15bcer061
- */
- public class insert extends HttpServlet {
- /**
- * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html");
- PrintWriter out=response.getWriter();
- int id=1;
- String name=request.getParameter("name");
- String add=request.getParameter("add");
- String num=request.getParameter("no");
- String edu=request.getParameter("edu");
- String per=request.getParameter("per");
- String coc=request.getParameter("coc");
- String boc=request.getParameter("boc");
- String cer=request.getParameter("cer");
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/add","root","");
- PreparedStatement pst=con.prepareStatement("insert into ins values(?,?,?,?,?,?,?,?,?)");
- pst.setInt(1, id);
- pst.setString(2, name);
- pst.setString(3, num);
- pst.setString(4, edu);
- pst.setString(5, per);
- pst.setString(6, coc);
- pst.setString(7, boc);
- pst.setString(8, cer);
- pst.setString(9, add);
- int ic=pst.executeUpdate();
- id++;
- }
- catch (ClassNotFoundException | SQLException ex) {
- Logger.getLogger(insert.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- /**
- * Handles the HTTP <code>POST</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- }
Add Comment
Please, Sign In to add comment