@WebServlet(name = "ServletBlog", urlPatterns = "/posts") public class Servlets extends HttpServlet { { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3300/db","root","root"); PreparedStatement preparedStatement = null; ResultSet resultSet = preparedStatement.executeQuery("SELECT * FROM db")) { } catch (SQLException e) { System.err.println("DB CONNECT ERROR"); } loaded driver in Classpath (in intellij idea (mysql-connector-java-5.1.39-bin.jar)) but still writes "DB CONNECT ERROR"
example exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3300/db