java - 找不到适用于 jdbc :mysql//localhost/sakila 的合适驱动程序

标签 java mysql jdbc

我正在尝试设置 JDBC,但收到此错误。

我尝试在 pom.xml 中添加依赖项,甚至 jar 文件都不起作用。我尝试了前面问题中提到的方法,没有任何效果。

public class FilmLength {

public static void main(String[] args) throws SQLException  {
    Connection dbCon = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    String url = "jdbc:mysql//localhost:3306/sakila";
    String username = "devuser";
    String password = "Demo@123";
    String query = "select * from film ";


    try {
        Class.forName("com.mysql.jdbc.Driver"); 
        dbCon = DriverManager.getConnection(url,username,password);
        st = dbCon.prepareStatement(query);
        rs = st.executeQuery();
        while(rs.next()) {
            String title = rs.getString(1);
            System.out.println(title);
        }
    } catch (Exception e) {

        e.printStackTrace();
    }
    finally {
        dbCon.close();
        st.close();
        rs.close();
    }



}

}

最佳答案

而不是 String url = "jdbc:mysql//localhost:3306/sakila";

应该是 String url = "jdbc:mysql://localhost:3306/sakila";

关于java - 找不到适用于 jdbc :mysql//localhost/sakila 的合适驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56380584/

相关文章:

Java 控制台程序

PHP 和数据库之间的 Java 桥梁

MySQL查询匹配两个字段并且有另一个共同字段

mysql - 优化 mySQL 查询 - 更新 JOIN 2 表

java - Spring 响应实体

java - Jsoup 选择包含 html 标签的文本

java - JDBC:连接返回NULL,怎么办?

java - MSSQL Server 2005-JDBC连接

oracle - 在 Quercus/Tomcat 上使用 Zend 并连接到 Oracle

java - 带有Gradle的Intellij中的调试器配置