简体   繁体   English

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

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

I'm trying to set up JDBC but I'm getting this error. 我正在尝试设置JDBC,但出现此错误。

I tried adding the dependency in pom.xml and even jar file nothing works. 我尝试在pom.xml甚至jar文件中添加依赖项,但没有任何效果。 I tried the methods mentioned in previous questions, nothing works. 我尝试了前面问题中提到的方法,但没有任何效果。

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();
    }



}

}

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

it should be String url = "jdbc:mysql://localhost:3306/sakila"; 它应该是String url = "jdbc:mysql://localhost:3306/sakila";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到适用于jdbc:mysql:// localhost /的驱动程序<myDB> - No suitable driver found for jdbc:mysql://localhost/<myDB> 找不到适合 jdbc 的驱动程序:mysql://localhost/database - No suitable driver found for jdbc:mysql://localhost/database 找不到适用于jdbc:mysql:// localhost /的驱动程序 - No suitable driver found for jdbc:mysql://localhost/ JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting - JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM