java - 找不到适合 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";
推荐阅读
- android - 系统“UI 已停止”MediaSessionCompat
- javafx - 如何将隐藏的整数值分配给 RadioButton?
- ios - 如何使用 Xamarin 和 iOS 控制背景音频
- firebase - 尝试使用反应原生谷歌登录登录时出错
- kubernetes - EKS:无法从 pod 中提取日志
- python - 为什么有一个程序的 .cfg 文件?
- java - 如何解决请求超时
- sql - MS Access SQL:获取具有最高版本和修订的数据集
- c++ - C++ - 如何从具有 const 大小的算术类型数组创建类构造函数?
- delphi - system.str 的警告