【问题标题】:No suitable driver found for jdbc:mysql//localhost/sakila找不到适合 jdbc:mysql//localhost/sakila 的驱动程序
【发布时间】:2019-10-16 05:56:26
【问题描述】:

我正在尝试设置 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();
    }



}

}

【问题讨论】:

    标签: java mysql jdbc


    【解决方案1】:

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

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

    【讨论】:

    • 您应该指出评论中的错别字并投票/标记以关闭,而不是回答。
    猜你喜欢
    • 2014-08-05
    • 2018-12-13
    • 2016-10-01
    • 2012-05-08
    • 2017-08-26
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多