How to resolve “Cannot create JDBC driver of class ‘com.mysql.jdbc.Driver’ for connect URL”

Firstly I want to say that i checked all answers at stackoverflow, and i can’t fix this bug! Help me please! I spend a lot of time, but no result. I’m trying to create connection pool using Tomcat8. I have an exception:

java.sql.SQLException: Cannot create JDBC driver of class ‘com.mysql.jdbc.Driver’ for connect URL ‘jdbc:mysql:/localhost:3306/autopark’ at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory( at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource( at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection( at ua.khpi.shapoval.db.DbConnector.init( at ua.khpi.shapoval.db.DbContextListner.contextInitialized( at org.apache.catalina.core.StandardContext.listenerStart( at org.apache.catalina.core.StandardContext.startInternal( at org.apache.catalina.util.LifecycleBase.start( at org.apache.catalina.core.ContainerBase$ at org.apache.catalina.core.ContainerBase$ at at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at Caused by: java.sql.SQLException: No suitable driver at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory( … 13 more


public class DbConnector {
    private static Logger log = Logger.getLogger(DbConnector.class.getName());
    private static DataSource dataSource;
    private static Connection connection;

    public static void init() throws ServletException, SQLException, NamingException, ClassNotFoundException {

        Context initCtx = new InitialContext();

        Context envCtx = (Context) initCtx.lookup("java:comp/env/");

        DataSource ds = (DataSource) envCtx.lookup("jdbc/autopark");

    public static Connection getConnection() throws SQLException {

        return dataSource.getConnection();


context.xml that located in META-INF folder

    <?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true" reloadable="true">
    <Resource name="jdbc/autopark" auth="Container" type="javax.sql.DataSource"
        username="root" password="161acid161" driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql:/localhost:3306/autopark" maxActive="15" maxIdle="3" />
    <ResourceLink name="jdbc/autopark" global="jdbc/autopark"

        type="javax.sql.DataSource" />


web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
    id="WebApp_ID" version="3.1">










Content of my tomcat/lib directory and my project structure. enter image description here

enter image description here

The JDBC URL is not correct, indeed you have a missing slash so try this:


If you check well the real error is No suitable driver which means that it cannot find any JDBC driver that supports the provided URL.

About Nguyễn Viết Hiền

Passionate, Loyal
This entry was posted in Education and Training, Java, Knowledge, Problem solving, Programming, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s