簡體   English   中英

找不到適用於jdbc的驅動程序:mysql // localhost / sakila

[英]No suitable driver found for jdbc:mysql//localhost/sakila

我正在嘗試設置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";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM