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插件。有谁知道它为什么会发生?在启动代理之前是否还需要进行其他配置?
答案 0 :(得分:0)
主要问题是EJADE插件和Eclipse最新版本之间存在某种不兼容性:Juno。我改为Eclipse Indigo,一切正常!