繁体   English   中英

JADE和JDBC MySQL连接给classnotfound异常

[英]JADE and JDBC MySQL connection giving classnotfound exception

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插件。 有人知道为什么会这样吗? 启动代理之前是否还需要进行其他配置?

主要问题是EJADE插件和Eclipse最新版本Juno之间存在某种不兼容。 我改用Eclipse Indigo,一切正常!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM