protected void setup() {
System.out.println("Hello Buyer Agent "+getAID().getName()+" is now ready....");
String url = "jdbc:mysql://localhost/";
String dbName = "testdb";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "pass";
try {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
Statement st = conn.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM requested_electric_prods ORDER BY created DESC LIMIT 1");
while (res.next()) {
elec_pro_name = res.getString("search_string");
elec_pro_requested_min_price = res.getInt("price_min");
elec_pro_requested_max_price = res.getInt("price_max");
System.out.println("Customer requested, product: "+ elec_pro_name + " min price: "+ elec_pro_requested_min_price + " max price: " + elec_pro_requested_max_price);
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
これが私の設定方法です。それは本当に簡単です。しかし、それでもデータベースに接続しようとすると、classNotFoundException が発生します。
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
JDBC ドライバーがあり、ビルド パスに既に追加されています。私は Eclipe と EJADE プラグインを使用しています。なぜそれが起こっているのか誰にも分かりますか?エージェントを開始する前に、他に必要な構成はありますか?