简体   繁体   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();
       }

This is my setup method. 这是我的设置方法。 It is really simple. 真的很简单。 But still when it tries to connect to database it gives classNotFoundException. 但是仍然在尝试连接数据库时给出classNotFoundException。

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I have JDBC driver and already added it to build path. 我有JDBC驱动程序,并且已经将其添加到构建路径中。 I am using Eclipe and EJADE plugin. 我正在使用Eclipe和EJADE插件。 Does anyone know why it is happening? 有人知道为什么会这样吗? Are there any more configurations needed to do before starting the agent? 启动代理之前是否还需要进行其他配置?

Main problem had been some kind of a incompatibility between the EJADE plugin and Eclipse latest version: Juno. 主要问题是EJADE插件和Eclipse最新版本Juno之间存在某种不兼容。 I changed to Eclipse Indigo and everything worked fine! 我改用Eclipse Indigo,一切正常!

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

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