java - 找不到 JDBC 驱动程序

标签 java jdbc

try
        {
            String userName = "root";
            String password = "";
            //<facility> is my database
            String url = "jdbc:mysql://localhost/facility";
            Class.forName ("com.mysql.jdbc.Driver").newInstance ();
            conn = DriverManager.getConnection (url, userName, password);
            System.out.println ("Database connection established");
        }
        catch (Exception e)
        {
            System.out.println ("Cannot connect to database server " +e.getClass().getName());

        }

输出> 无法连接到数据库服务器 java.lang.ClassNotFoundException

最佳答案

看来您应该将 MySQL 驱动程序 jar 放入您的类路径中。

关于java - 找不到 JDBC 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5390604/

相关文章:

java - SonarQube 中的连接池配置/错误

java - tomEE 知道 Maven 依赖吗?

java - SQL blob 数据转义导致 max_allowed_pa​​cket 错误

java - 无法解决 "java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index"错误

java - Sonar 提示 "The diamond operator ("< >") should be used"

java - 使用列表填充 jTable

java - mysql访问被jdbc拒绝

java - 使用maven编译时将xml文件从src/复制到class/

java - 按计划运行所有派生 DAO 类的公共(public)查询

java - 创建名称为 'securityConfig' 的 bean 时出错 : Injection of autowired dependencies failed