I am trying to stablish connection with mysql database to servlet and here is my code. It is taking 20-25 seconds to compile befor showing the result on browser and it directly goes inside catch block. I can not understand what is the wrong I did. I checked database name, included mysql connector in library folder of eclipse IDE. Please need help.
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/registration")
public class Registration extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:1234/registration","root","4221");
out.print("Database Updated");
}catch(Exception e) {
e.printStackTrace();
out.print("Database is not updated");
}
out.close();
}
}