Guest User

Untitled

a guest
Feb 14th, 2020
50
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.annotation.WebServlet;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. /**
  16. *
  17. * @author User_30
  18. */
  19. @WebServlet(urlPatterns = {"/NewServlet"})
  20. public class NewServlet extends HttpServlet {
  21.  
  22. /**
  23. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  24. * methods.
  25. *
  26. * @param request servlet request
  27. * @param response servlet response
  28. * @throws ServletException if a servlet-specific error occurs
  29. * @throws IOException if an I/O error occurs
  30. */
  31. protected static Connection initializeDatabase()
  32. throws SQLException, ClassNotFoundException {
  33. String dbDriver="com.sql.jdbc.Driver";
  34. String dbURL= "jdbc:mysql://localhost:3306/test?zeroDataBehavior=converttoNull";
  35. Class.forName(dbDriver);
  36. Connection con=DriverManager.getConnection(dbURL,"root","");
  37. out.println("<html><body><b>Successfully connected"+ "</br></body></html>");
  38. return con;
  39. }
  40. }
  41.  
  42.  
  43.  
  44. }
RAW Paste Data