Java 未找到适合jdbc的驱动程序:mysql//localhost/sakila
我正在尝试设置JDBC,但遇到了这个错误 我尝试在pom.xml和jar文件中添加依赖项,但没有效果。我尝试了前面问题中提到的方法,但没有任何效果Java 未找到适合jdbc的驱动程序:mysql//localhost/sakila,java,mysql,jdbc,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;
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";代码>你不应该回答,而应该指出评论中的打字错误,并投票/标记关闭。