Zealous Zealous - 16 days ago 5
MySQL Question

Type mismatch: cannot convert from java.sql.Connection to com.mysql.jdbc.Connection

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

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

import com.mysql.jdbc.*;

*// Here,in below 2 statement, I got 2 the same error as shown in title*

**Connection con = DriverManager.getConnection("localhost:3306", "root","simple");
Statement stmt = con.createStatement();**
if(stmt.execute(sql)){
System.out.println("Sql Statement Executed.");
}
else
{
System.out.println("Sql Statement not eexecuted.");
}
if((unm != null) && (pwd != null)){
RequestDispatcher rd =request.getRequestDispatcher("Home.jsp");
rd.forward(request, response);
}
}

}


I am trying to send my data from servlet to mysql server but in servlet I got the

error : "Type mismatch: cannot convert from java.sql.Connection to com.mysql.jdbc.Connection"

Can anyone suggest me the way to remove the error for my code. I am not getting any idea.

Answer

Remove the import com.mysql.jdbc.* and use import java.sql.Connection. I think it would be ok.