简体   繁体   中英

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.

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

I have JDBC driver and already added it to build path. I am using Eclipe and EJADE plugin. 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. I changed to Eclipse Indigo and everything worked fine!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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