Hello everyone i am developing simple jsp file which takes some info from students like name,gender,skills etc and i am directing it to servlet and given database connections her.But when i run the code its not connecting to db. Can some one please help me out. Here is my servlet code
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con=null;
String url ="jdbc:mysql://localhost:3306/";
String dbName="student_db";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String password = "admin";
String bttn_value = request.getParameter("submit");
if(bttn_value.equalsIgnoreCase("submit"))
{
String name = request.getParameter("fname");
String gender = request.getParameter("gender");
String skill ="";
System.out.println("2222222222");
String skills[]= request.getParameterValues("skill");
for(int i=0;i<skills.length;i++)
{
skill +=skills[i]+",";
}
String addr=request.getParameter("adname");
String country = request.getParameter("country");
Statement stmt;
try
{
System.out.println("444444444444");
Class.forName(driver).newInstance();
System.out.println("333333333");
con = DriverManager.getConnection(url + dbName, username,
password);
System.out.print("Connected to database");
String query1= "insert into student values name='"
+name +"',gender='"+gender+ "',skills='"+skill + "',addname='"
+addr +"',country='" +country +"'";
stmt =con.createStatement();
stmt.executeUpdate(query1);
out.print("<br>");
response.sendRedirect("std.jsp");
con.close();
System.out.print("Disconnected from DB");
}
catch (Exception e)
{
out.println(e.getMessage());
System.out.println("123456");
}
and here is my console

and the output what i am getting

Thank you in advance, any help is appreciable.
The code does not need to create a new instance to register the driver.
Class.forName(driver);will suffice.Also make sure the MySql JDBC driver is in your classpath. You can download the jar or pull it in from maven.
Maven
Direct Download
To import the jar, first download the jar file and place it within your file system, preferably within your project.
Java Build Path.Librariestab and click Add JARs (if .jar is inyour project) or Add External Jars (if .jar is outside).
To get more useful debugging information, try printing the stacktrace in your catch, this can be removed once the problem is resolved. I suspect it will tell you that it cannot find the mysql driver.
If your issue is still not resolved, post this stacktrace with your question.