Najwa K. Semdina
Najwa K. Semdina

Reputation: 71

How can I obtain MySQL Connector Java Maven Dependency

I have downloaded MySQL Workbench for my database, and IntelliJ for the JDBC. However, while watching a tutorial, it was mentioned that I need the MySQL dependency in a pom.xml file. Any idea on how to obtain that?

Upvotes: 5

Views: 46573

Answers (3)

Andrew
Andrew

Reputation: 31

For me the issue was that:

  1. Add the MySQL connector-j dependency in you pom.xml:

    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <scope>runtime</scope>
    </dependency>
    
  2. Add your database URL and configuration in the application.properties file:

    spring.datasource.url=jdbc:mysql://localhost:3306/database-name
    spring.datasource.username=database-User-name
    spring.datasource.password=your-database-password
    

Upvotes: 0

Basil Bourque
Basil Bourque

Reputation: 340230

To connect to a MySQL database server from a Java app, you need a JDBC driver. The MySQL Connector/J product is one such JDBC driver.

You can obtain MySQL Connector/J via Maven. Look at a Maven repository for the <dependency> XML fragment. Copy-paste that within the <dependencies> tag of your POM file.

For example, look at MvnRepository.com.

As of 8.0.29:

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.0.29</version>
</dependency>

Before version 8.0.29:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.24</version>
</dependency>

A POM file is the place to configure a project whose build is driven by Apache Maven. Maven is one of the most popular build tools. Another is Apache Gradle, which provides dependency management via the same Maven repositories.

Upvotes: 12

Subha Chandra
Subha Chandra

Reputation: 781

Just add the MySQL dependency in pom.xml files

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

Upvotes: 3

Related Questions