简体   繁体   中英

Maven mysql-connector dependency doesnt work

This is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>id</groupId>
    <artifactId>jbdc_project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>

    </build>

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

I tried to connect to MySQL database:

public class Main {
    public static void main(String[] args) {
        String url = "jbdc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false";
        String user = "root";
        String password = "root";

        try{
            Connection myConn = DriverManager.getConnection(url,user,password);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

And i get this error:

java.sql.SQLException: No suitable driver found for jbdc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false

Any ideas on how to fix it?

Got it.

There's a typo in your JDBC URL. It should be 'jdbc' instead of 'jbdc'.

String url = "jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM