You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetBeans中使用JDBC连接MySQL时出现“No suitable driver found”错误

JDBC连接MySQL报错:No suitable driver found

我刚开始学习Java,尝试用JDBC连接MySQL数据库,已经把Connector文件添加到项目库了,但还是出现“No suitable driver found”错误。

相关代码

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
    static String user ="root";
    static String password="12345";
    static String url = "jbdc:mysql://localhost:3306/world";
    public static void main(String[] args) throws ClassNotFoundException  {

        Connection connection=null;
    
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection=DriverManager.getConnection(url, user, password);
            System.out.println("baglanti basarili");
        } catch (SQLException e) {
            System.out.println(e);
        }
    }
}

解决办法

  • 修正URL拼写:你的数据库连接URL里把jdbc写成了jbdc,这是导致报错的直接原因,把URL改成jdbc:mysql://localhost:3306/world
  • 确认驱动类与Connector版本匹配:如果你的MySQL版本是8.0及以上,使用com.mysql.cj.jdbc.Driver是正确的,但要确保Connector jar包版本是8.0.x系列,不能混用旧版本驱动
  • 检查依赖引入是否生效:确认Connector jar包已经正确添加到项目的类路径中,在IDE里要通过“Add as Library”的方式添加,而不是单纯把jar包复制到项目文件夹
  • 验证MySQL服务状态:确保本地MySQL服务处于运行状态,端口3306没有被其他程序占用

内容的提问来源于stack exchange,提问作者kadir cali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 09:10:11