私は Mac を使用しており、MySQL の MAMP インスタンスを実行しています。jdbc ドライバーを使用して Java コードを「test」というデータベースに接続し、「customer」というテーブルを操作しようとしています。エラーが発生し続けます:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:8889/test
問題が私のコードにあるのか、それとも MySQL の MAMP インスタンスの構成の問題なのか、それともまったく別の問題なのかはわかりません。
初期化ドライバーメソッドがあります:
public void initializeDriver(){
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.err.println(e.toString());
}
}
そして、次の方法で作成された接続があります。
public void insertCustomer(String connectionUrl, String connectionUser, String connectionPassword, Customer customer) {
try{
Connection conn = DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
Statement constat = conn.createStatement();
String query = "INSERT INTO customers (customer_id, email, deliverable, create_date) VALUES (" + customer.id + ", " + customer.emailAddress + ", " + customer.deliverable + ", " + customer.createDate + ")" ;
constat.executeQuery(query);
conn.close();
}
catch(SQLException e){
System.out.println(e.toString());
}
}
そして、mysql-connector-java-5.1.20 をダウンロードしてクラスパスに設定しました。
このエラーを修正する方法について何か提案があれば、本当に感謝しています!