package es.pulsoft.conexion;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		String url = "jdbc:mysql://localhost:3306/escuela?useSSL=false";
        String user = "root";
        String password = "*prueba2024*";
        
        String driver="com.mysql.cj.jdbc.Driver";
        try {
        	PrintWriter out =response.getWriter();
        	out.print("Nombre de la base de datos " + url + "<br>");
        	Class.forName(driver);
        	Connection miConexion=DriverManager.getConnection(url,user,password);
        	out.print("Conectado");
        	miConexion.close();
        }catch(Exception e) {
        	e.printStackTrace();
        }
	}

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

}
