🌐
MySQL
dev.mysql.com › downloads › connector › j
MySQL :: Download Connector/J
MySQL Connector/J is the official JDBC driver for MySQL. MySQL Connector/J 8.0 and higher is compatible with all MySQL versions starting with MySQL 5.7.
Documentation
X DevAPI API for MySQL Shell and Connectors supporting the X Protocol · X DevAPI User Guide · X DevAPI User Guide for MySQL Shell in JavaScript Mode · X DevAPI User Guide for MySQL Shell in Python Mode · MySQL Connector/C++ X DevAPI Reference · MySQL Connector/J X DevAPI Reference ·
MySQL
31 Connectors and APIs · 31.1 MySQL Connector/C++ 31.2 MySQL Connector/J · 31.3 MySQL Connector/NET · 31.4 MySQL Connector/ODBC · 31.5 MySQL Connector/Python · 31.6 MySQL Connector/Node.js · 31.7 MySQL C API · 31.8 MySQL PHP API · 31.9 MySQL Perl API ·
APT Repository
MySQL Connector/C++ MySQL Connector/J · MySQL Connector/ODBC · MySQL Connector/Python · Online Documentation: Installing MySQL on Linux Using the MySQL APT Repository · Please report any bugs or inconsistencies you observe to our Bugs Database.
Download MySQL Workbench
Packages for Sequoia (15) are compatible with Sonoma (14) · We suggest that you use the MD5 checksums and GnuPG signatures to verify the integrity of the packages you download
🌐
MySQL
mysql.com › products › connector
MySQL :: MySQL Connectors
MySQL provides standards-based drivers for JDBC, ODBC, and .Net enabling developers to build database applications in their language of choice. In addition, a native C library allows developers to embed MySQL directly into their applications · These drivers are developed and maintained by ...
People also ask

Which jar file is the MySQL JDBC driver?
MySQL Connector/J (mysql-connector-j). Download the zip from this page and load the jar in Driver Manager.
🌐
dbschema.com
dbschema.com › jdbc drivers › mysql
MySQL JDBC Driver Download & Connector/J URL | DbSchema
What is the default MySQL JDBC URL?
jdbc:mysql://host:3306/database with optional SSL and timezone parameters.
🌐
dbschema.com
dbschema.com › jdbc drivers › mysql
MySQL JDBC Driver Download & Connector/J URL | DbSchema
Does MariaDB use the same driver?
MariaDB is MySQL-compatible; see the MariaDB JDBC page for connector details.
🌐
dbschema.com
dbschema.com › jdbc drivers › mysql
MySQL JDBC Driver Download & Connector/J URL | DbSchema
🌐
Maven Repository
mvnrepository.com › artifact › mysql › mysql-connector-java
Maven Repository: mysql » mysql-connector-java
April 18, 2023 - MySQL Connector/J is a JDBC Type 4 driver, which means that it is pure Java implementation of the MySQL protocol and does not rely on the MySQL client libraries.
🌐
GitHub
github.com › mysql › mysql-connector-j
GitHub - mysql/mysql-connector-j: MySQL Connector/J · GitHub
MySQL provides connectivity for client applications developed in the Java programming language with MySQL Connector/J, a driver that implements the Java Database Connectivity (JDBC) API and also MySQL X DevAPI.
Author   mysql
🌐
MySQL
dev.mysql.com › doc › connector-j › en › connector-j-usagenotes-connect-drivermanager.html
MySQL :: MySQL Connector/J Developer Guide :: 7.1 Connecting to MySQL Using the JDBC DriverManager Interface
If testing this code, first read the installation section at Chapter 4, Connector/J Installation, to make sure you have connector installed correctly and the CLASSPATH set up. Also, ensure that MySQL is configured to accept external TCP/IP connections. import java.sql.Connection; import ...
🌐
Maven Central
central.sonatype.com › artifact › mysql › mysql-connector-java
Maven Central: mysql:mysql-connector-java
Discover mysql-connector-java in the mysql namespace. Explore metadata, contributors, the Maven POM file, and more.
Find elsewhere
🌐
Maven Central
central.sonatype.com › artifact › com.mysql › mysql-connector-j
Maven Central: com.mysql:mysql-connector-j
Discover mysql-connector-j in the com.mysql namespace. Explore metadata, contributors, the Maven POM file, and more.
🌐
DbSchema
dbschema.com › jdbc drivers › mysql
MySQL JDBC Driver Download & Connector/J URL | DbSchema
Download MySQL Connector/J, configure jdbc:mysql:// URLs, and connect MySQL to DbSchema. Driver jar and setup guide.
🌐
MySQL
downloads.mysql.com › archives › c-j
MySQL :: Download MySQL Connector/J (Archived Versions)
Please note that these are old versions. New releases will have recent bug fixes and features! To download the latest release of MySQL Connector/J, please visit MySQL Downloads.
🌐
MySQL
dev.mysql.com › doc › connector-j › en › connector-j-installing.html
MySQL :: MySQL Connector/J Developer Guide :: 4 Connector/J Installation
Third-party Libraries: According to how you use Connector/J 9.7, you may also need to install the following third-party libraries on your system for it to work: Protocol Buffers (protobuf-java) 4.31.1 is required for using X DevAPI
🌐
Maven Repository
mvnrepository.com › artifact › com.mysql › mysql-connector-j
Maven Repository: com.mysql » mysql-connector-j
April 22, 2026 - MySQL Connector/J is a JDBC Type 4 driver, which means that it is pure Java implementation of the MySQL protocol and does not rely on the MySQL client libraries.
Top answer
1 of 14
548

Here's a step by step explanation how to install MySQL and JDBC and how to use it:

  1. Download and install the MySQL server. Just do it the usual way. Remember the port number whenever you've changed it. It's by default 3306.

  2. Download the JDBC driver and put in classpath, extract the ZIP file and put the containing JAR file in the classpath. The vendor-specific JDBC driver is a concrete implementation of the JDBC API (tutorial here).

    If you're using an IDE like Eclipse or Netbeans, then you can add it to the classpath by adding the JAR file as Library to the Build Path in project's properties.

    If you're doing it "plain vanilla" in the command console, then you need to specify the path to the JAR file in the -cp or -classpath argument when executing your Java application.

    java -cp .;/path/to/mysql-connector.jar com.example.YourClass

    The . is just there to add the current directory to the classpath as well so that it can locate com.example.YourClass and the ; is the classpath separator as it is in Windows. In Unix and clones : should be used.

    If you're developing a servlet based WAR application and wish to manually manage connections (poor practice, actually), then you need to ensure that the JAR ends up in /WEB-INF/lib of the build. See also How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib. The better practice is to install the physical JDBC driver JAR file in the server itself and configure the server to create a JDBC connection pool. Here's an example for Tomcat: How should I connect to JDBC database / datasource in a servlet based application?

  3. Create a database in MySQL. Let's create a database javabase. You of course want World Domination, so let's use UTF-8 as well.

     CREATE DATABASE javabase DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    
  4. Create a user for Java and grant it access. Simply because using root is a bad practice.

     CREATE USER 'java'@'localhost' IDENTIFIED BY 'password';
     GRANT ALL ON javabase.* TO 'java'@'localhost' IDENTIFIED BY 'password';
    

    Yes, java is the username and password is the password here.

  5. Determine the JDBC URL. To connect the MySQL database using Java you need an JDBC URL in the following syntax:

    jdbc:mysql://hostname:port/databasename
    • hostname: The hostname where MySQL server is installed. If it's installed at the same machine where you run the Java code, then you can just use localhost. It can also be an IP address like 127.0.0.1. If you encounter connectivity problems and using 127.0.0.1 instead of localhost solved it, then you've a problem in your network/DNS/hosts config.

    • port: The TCP/IP port where MySQL server listens on. This is by default 3306.

    • databasename: The name of the database you'd like to connect to. That's javabase.

    So the final URL should look like:

    jdbc:mysql://localhost:3306/javabase
  6. Test the connection to MySQL using Java. Create a simple Java class with a main() method to test the connection.

     String url = "jdbc:mysql://localhost:3306/javabase";
     String username = "java";
     String password = "password";
    
     System.out.println("Connecting database ...");
    
     try (Connection connection = DriverManager.getConnection(url, username, password)) {
         System.out.println("Database connected!");
     } catch (SQLException e) {
         throw new IllegalStateException("Cannot connect the database!", e);
     }
    

    If you get a SQLException: No suitable driver, then it means that either the JDBC driver wasn't autoloaded at all or that the JDBC URL is wrong (i.e. it wasn't recognized by any of the loaded drivers). See also The infamous java.sql.SQLException: No suitable driver found. Normally, a JDBC 4.0 driver should be autoloaded when you just drop it in runtime classpath. To exclude one and other, you can always manually load it as below:

     System.out.println("Loading driver ...");
    
     try {
         Class.forName("com.mysql.cj.jdbc.Driver"); // Use com.mysql.jdbc.Driver if you're not on MySQL 8+ yet.
         System.out.println("Driver loaded!");
     } catch (ClassNotFoundException e) {
         throw new IllegalStateException("Cannot find the driver in the classpath!", e);
     }
    

    Note that the newInstance() call is not needed here. It's in case of MySQL just to fix the old and buggy org.gjt.mm.mysql.Driver. Explanation here. If this line throws ClassNotFoundException, then the JAR file containing the JDBC driver class is simply not been placed in the classpath. Please also note that it's very important to throw an exception so that the code execution is immediately blocked, instead of suppressing it of merely printing the stack trace and then continuing the rest of the code.

    Also note that you don't need to load the driver everytime before connecting. Just only once during application startup is enough.

    If you get a SQLException: Connection refused or Connection timed out or a MySQL specific CommunicationsException: Communications link failure, then it means that the DB isn't reachable at all. This can have one or more of the following causes:

    1. IP address or hostname in JDBC URL is wrong.
    2. Hostname in JDBC URL is not recognized by local DNS server.
    3. Port number is missing or wrong in JDBC URL.
    4. DB server is down.
    5. DB server doesn't accept TCP/IP connections.
    6. DB server has run out of connections.
    7. Something in between Java and DB is blocking connections, e.g. a firewall or proxy.

    To solve the one or the other, follow the following advices:

    1. Verify and test them with ping.
    2. Refresh DNS or use IP address in JDBC URL instead.
    3. Verify it based on my.cnf of MySQL DB.
    4. Start the DB.
    5. Verify if mysqld is started without the --skip-networking option.
    6. Restart the DB and fix your code accordingly that it closes connections in finally.
    7. Disable firewall and/or configure firewall/proxy to allow/forward the port.

    Note that closing the Connection is extremely important. If you don't close connections and keep getting a lot of them in a short time, then the database may run out of connections and your application may break. Always acquire the Connection in a try-with-resources statement. This also applies to Statement, PreparedStatement and ResultSet. See also How often should Connection, Statement and ResultSet be closed in JDBC?

That was it as far the connectivity concerns. You can find here a more advanced tutorial how to load and store fullworthy Java model objects in a database with help of a basic DAO class.


Using a Singleton Pattern and/or a static variable for the DB Connection is a bad practice. See among others Is it safe to use a static java.sql.Connection instance in a multithreaded system? This is a #1 starters mistake. Make sure you don't fall in this trap.

2 of 14
233

DataSource

DriverManager is a fairly old way of doing things. The better way is to get a DataSource object. Either by using JNDI to look one up that your app server container already configured for you:

Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/myDB");

… or by instantiating and configuring one from your database driver directly, such as com.mysql.cj.jdbc.MysqlDataSource (see documentation):

MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("scott");
dataSource.setPassword("tiger");
dataSource.setServerName("myDBHost.example.org");

… and then obtain connections from it, same as above:

Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ID FROM USERS");
…
rs.close();
stmt.close();
conn.close();

In modern Java, use try-with-resources syntax to automatically close JDBC resources (now AutoCloseable).

try (
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT ID FROM USERS");
) {
    …
}
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-database-connectivity-with-mysql
Java Database Connectivity with MySQL - GeeksforGeeks
October 4, 2025 - Java JDK installed on your system. ... Search for MySQL Community Downloads. Go to Connector/J.
🌐
OneUptime
oneuptime.com › home › blog › how to configure mysql connector/j (java jdbc driver)
How to Configure MySQL Connector/J (Java JDBC Driver)
March 31, 2026 - Configure MySQL Connector/J for production Java applications with connection pooling, SSL, performance tuning, and failover settings.
🌐
MariaDB
mariadb.com › docs › connectors › mariadb-connector-j › about-mariadb-connector-j
About MariaDB Connector/J Guide | Connectors | MariaDB Documentation
1 week ago - MariaDB Connector/J releases older than 1.2.0 may be compatible with server versions older than MySQL 5.5, but those MariaDB Connector/J releases aren't supported anymore. To determine which MariaDB Connector/J release series would be best to use for each Java version, please see the following ...
🌐
Reddit
reddit.com › r/springboot › mysql-connector-java vs mysql-connector-j maven dependency
r/SpringBoot on Reddit: mysql-connector-java vs mysql-connector-j maven dependency
March 12, 2023 -

What is different from maven dependency

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

indicated as connector for mysql into spring boot documentation and maven dependecy

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>x.y.z</version>
</dependency>

indicated as connector for mysql into mysql documentation ? Are the same thing?

🌐
MySQL
dev.mysql.com › doc › connector-j › en
MySQL :: MySQL Connector/J Developer Guide
This manual describes how to install, configure, and develop database applications using MySQL Connector/J 9.7, a JDBC and X DevAPI driver for communicating with MySQL servers.
🌐
Jar-Download
jar-download.com › home › mysql › mysql-connector-java
Download mysql JAR files with all dependencies
Download mysql JAR files ✓ With dependencies ✓ Documentation ✓ Source code
🌐
MySQL
dev.mysql.com › blog-archive › mysql-connector-j-8-0-25
MySQL :: MySQL Connector/J 8.0.25 has been released
May 11, 2021 - Dear MySQL users, MySQL Connector/J 8.0.25 is the latest General Availability release of the MySQL Connector/J 8.0 series. It is suitable for use with MySQL Server versions 8.0, 5.7, and 5.6. It supports the Java Database Connectivity (JDBC) 4.2 API, and implements the X DevAPI.