No suitable driver found for jdbc:mysql://localhost:3306/bookexample
时间: 2024-06-14 13:04:02 浏览: 117
```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcExample {
public static void main(String[] args) {
Connection connection = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/bookexample";
String username = "your_username";
String password = "your_password";
connection = DriverManager.getConnection(url, username, password);
System.out.println("Connected to the database");
} catch (ClassNotFoundException e) {
System.out.println("MySQL JDBC Driver not found");
e.printStackTrace();
} catch (SQLException e) {
System.out.println("Connection failed");
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
```
阅读全文