Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Hello Friends,

You may have come across “java.lang.ClassNotFoundException: com.mysql.jdbc.Driver” error/exception while working with java and JDBC. The error occurs mainly when we try to connect to the mySql database from our java code. The error message itself give the clear indication about what we are missing. It says that it is unable to find the Class – “com.mysql.jdbc.Driver”.

Now, this exception is mainly due to unavailability of the mysql-connector jar file which contains the required class which is missing while the compilation of the code. This jar file contains many other classes those are listed in the below table

com.mysql.jdbc.AssertionFailedException.class
com.mysql.jdbc.Blob.class
com.mysql.jdbc.BlobFromLocator.class
com.mysql.jdbc.Buffer.class
com.mysql.jdbc.CachedResultSetMetaData.class
com.mysql.jdbc.CallableStatement.class
com.mysql.jdbc.CharsetMapping.class
com.mysql.jdbc.Clob.class
com.mysql.jdbc.CommunicationsException.class
com.mysql.jdbc.CompressedInputStream.class
com.mysql.jdbc.Connection.class
com.mysql.jdbc.ConnectionFeatureNotAvailableException.class
com.mysql.jdbc.ConnectionProperties.class
com.mysql.jdbc.ConnectionPropertiesTransform.class
com.mysql.jdbc.Constants.class
com.mysql.jdbc.CursorRowProvider.class
com.mysql.jdbc.DatabaseMetaData.class
com.mysql.jdbc.DatabaseMetaDataUsingInfoSchema.class
com.mysql.jdbc.DocsConnectionPropsHelper.class
com.mysql.jdbc.Driver.class
com.mysql.jdbc.EscapeProcessor.class
com.mysql.jdbc.EscapeProcessorResult.class
com.mysql.jdbc.EscapeTokenizer.class
com.mysql.jdbc.ExportControlled.class
com.mysql.jdbc.Field.class
com.mysql.jdbc.LicenseConfiguration.class
com.mysql.jdbc.LoadBalancingConnectionProxy.class
com.mysql.jdbc.Messages.class
com.mysql.jdbc.MiniAdmin.class
com.mysql.jdbc.MysqlDataTruncation.class
com.mysql.jdbc.MysqlDefs.class
com.mysql.jdbc.MysqlErrorNumbers.class
com.mysql.jdbc.MysqlIO.class
com.mysql.jdbc.MysqlParameterMetadata.class
com.mysql.jdbc.MysqlSavepoint.class
com.mysql.jdbc.NamedPipeSocketFactory.class
com.mysql.jdbc.NonRegisteringDriver.class
com.mysql.jdbc.NonRegisteringReplicationDriver.class
com.mysql.jdbc.NotImplemented.class
com.mysql.jdbc.NotUpdatable.class
com.mysql.jdbc.OperationNotSupportedException.class
com.mysql.jdbc.OutputStreamWatcher.class
com.mysql.jdbc.PacketTooBigException.class
com.mysql.jdbc.PingTarget.class
com.mysql.jdbc.PreparedStatement.class
com.mysql.jdbc.ReplicationConnection.class
com.mysql.jdbc.ReplicationDriver.class
com.mysql.jdbc.ResultSet.class
com.mysql.jdbc.ResultSetMetaData.class
com.mysql.jdbc.RowData.class
com.mysql.jdbc.RowDataDynamic.class
com.mysql.jdbc.RowDataStatic.class
com.mysql.jdbc.SQLError.class
com.mysql.jdbc.Security.class
com.mysql.jdbc.ServerPreparedStatement.class
com.mysql.jdbc.SingleByteCharsetConverter.class
com.mysql.jdbc.SocketFactory.class
com.mysql.jdbc.StandardSocketFactory.class
com.mysql.jdbc.Statement.class
com.mysql.jdbc.StringUtils.class
com.mysql.jdbc.TimeUtil.class
com.mysql.jdbc.UpdatableResultSet.class
com.mysql.jdbc.Util.class
com.mysql.jdbc.VersionedStringProperty.class
com.mysql.jdbc.WatchableOutputStream.class
com.mysql.jdbc.WatchableWriter.class
com.mysql.jdbc.WriterWatcher.class
com.mysql.jdbc.exceptions.MySQLDataException.class
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException.class
com.mysql.jdbc.exceptions.MySQLInvalidAuthorizationSpecException.class
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException.class
com.mysql.jdbc.exceptions.MySQLNonTransientException.class
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException.class
com.mysql.jdbc.exceptions.MySQLTimeoutException.class
com.mysql.jdbc.exceptions.MySQLTransactionRollbackException.class
com.mysql.jdbc.exceptions.MySQLTransientConnectionException.class
com.mysql.jdbc.exceptions.MySQLTransientException.class
com.mysql.jdbc.integration.c3p0.MysqlConnectionTester.class
com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter.class
com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker.class
com.mysql.jdbc.jdbc2.optional.CallableStatementWrapper.class
com.mysql.jdbc.jdbc2.optional.ConnectionWrapper.class
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.class
com.mysql.jdbc.jdbc2.optional.MysqlDataSource.class
com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory.class
com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection.class
com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.class
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.class
com.mysql.jdbc.jdbc2.optional.MysqlXAException.class
com.mysql.jdbc.jdbc2.optional.MysqlXid.class
com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.class
com.mysql.jdbc.jdbc2.optional.StatementWrapper.class
com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection.class
com.mysql.jdbc.jdbc2.optional.WrapperBase.class
com.mysql.jdbc.log.CommonsLogger.class
com.mysql.jdbc.log.Jdk14Logger.class
com.mysql.jdbc.log.Log.class
com.mysql.jdbc.log.Log4JLogger.class
com.mysql.jdbc.log.LogFactory.class
com.mysql.jdbc.log.LogUtils.class
com.mysql.jdbc.log.NullLogger.class
com.mysql.jdbc.log.StandardLogger.class
com.mysql.jdbc.profiler.ProfileEventSink.class
com.mysql.jdbc.profiler.ProfilerEvent.class
com.mysql.jdbc.util.BaseBugReport.class
com.mysql.jdbc.util.ErrorMappingsDocGenerator.class
com.mysql.jdbc.util.LRUCache.class
com.mysql.jdbc.util.PropertiesDocGenerator.class
com.mysql.jdbc.util.ReadAheadInputStream.class
com.mysql.jdbc.util.ResultSetUtil.class
com.mysql.jdbc.util.ServerController.class
com.mysql.jdbc.util.TimezoneDump.class
com.mysql.jdbc.util.VersionFSHierarchyMaker.class
org.gjt.mm.mysql.Driver.class

What you need to do is, just add the mysql-connector-java jar file in the build path of your program and then run the program again. Your program will run and execute properly. You can download the jar from MySql download link.

Hope this will help you.

Regards,

Nikhil Naoghare.

Related Posts

  • MySql Installation

    Hello Friends,   This is one of my tutorials related to database. You all must be familiar with MySQL, but still for those who have not learned about this, for them I will recall it in short. MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.The…

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.