我使用IntelJ所以我有这个代码(用户名和密码更改(:
String jdbcUrl = "jdbc:mysql://sql11.freesqldatabase.com:3306/sql11418144";
String username = "user1234";
String password = "abc";
Connection con = DriverManager.getConnection(jdbcUrl, username, password);
Statement stmt = con.createStatement();
String url = "select name from table";
ResultSet result = stmt.executeQuery(url);
while (result.next()) {
System.out.println(result.getString("name"));
}
我使用MySQL,我有以下配置:在此处输入图像描述
但我有这个错误:
java.sql.SQLException: No suitable driver found for jdbc:mysql://........
我能做什么?我可以在IntellJ中运行SELECT命令,但不能用JAVA??
您的连接字符串看起来不错。我假设您正在使用maven进行构建。如果是这样的话,你的.pom文件中是否包含以下内容?https://mvnrepository.com/artifact/mysql/mysql-connector-java
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>