Вопрос

I'm trying to connect to databse using jade java and jdbc

public class IntermediaryAgent extends Agent{

private Connection con;
protected void setup()
{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:xe","hr","hr");

    Statement stmt = con.createStatement();
    ResultSet rs=stmt.executeQuery("SELECT * FROM data");
    rs.next();

        int id=rs.getInt(1);
        String name=rs.getString("NAME");
        String surname=rs.getString("SURNAME");
        int age=rs.getInt(4);
        System.out.println(""+id+" "+name+" "+surname+" "+age);
        rs.close();
        stmt.close();
    con.close();
    DFAgentDescription df=new DFAgentDescription();
    df.setName(getAID());
    ServiceDescription sd =new ServiceDescription();
    sd.setType("Agent");
    sd.setName("inter");
    df.addServices(sd);
    try {
        DFService.register(this, df);
    } catch (FIPAException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
protected void takeDown()
{
    try {
        DFService.deregister(this);
    } catch (FIPAException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

But I get error

2012-05-24 18:15:27 jade.core.Runtime beginContainer
INFO: ----------------------------------
This is JADE snapshot - revision $WCREV$ of $WCDATE$
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
2012-05-24 18:15:29 jade.core.BaseService init
INFO: Service jade.core.management.AgentManagement initialized
2012-05-24 18:15:29 jade.core.BaseService init
INFO: Service jade.core.messaging.Messaging initialized
2012-05-24 18:15:29 jade.core.BaseService init
INFO: Service jade.core.mobility.AgentMobility initialized
2012-05-24 18:15:29 jade.core.BaseService init
INFO: Service jade.core.event.Notification initialized
2012-05-24 18:15:29 jade.core.messaging.MessagingService clearCachedSlice
INFO: Clearing cache
2012-05-24 18:15:29 jade.mtp.http.HTTPServer <init>
INFO: HTTP-MTP Using XML parser 
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
2012-05-24 18:15:29 jade.core.messaging.MessagingService boot
INFO: MTP addresses:
http://10.1.242.245:7778/acc
2012-05-24 18:15:29 jade.core.AgentContainerImpl joinPlatform
INFO: --------------------------------------
Agent container Main-Container@mariusz is ready.
--------------------------------------------
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at agenty.IntermediaryAgent.polacz(IntermediaryAgent.java:120)
at agenty.IntermediaryAgent.setup(IntermediaryAgent.java:19)
at jade.core.Agent$ActiveLifeCycle.init(Agent.java:1519)
at jade.core.Agent.run(Agent.java:1465)
at java.lang.Thread.run(Unknown Source)

    ***  Uncaught Exception for agent p  ***
    java.lang.NullPointerException
at agenty.IntermediaryAgent.odczyt(IntermediaryAgent.java:144)
at agenty.IntermediaryAgent.setup(IntermediaryAgent.java:20)
at jade.core.Agent$ActiveLifeCycle.init(Agent.java:1519)
at jade.core.Agent.run(Agent.java:1465)
at java.lang.Thread.run(Unknown Source)
ERROR: Agent p died without being properly terminated !!!
State was 2
jade.domain.FIPAAgentManagement.FailureException: ((action ( agent-identifier :name 
df@mariusz:1099/JADE  :addresses (sequence http://10.1.242.245:7778/acc )) (deregister 
(df-agent-description :name ( agent-identifier :name p@mariusz:1099/JADE  :addresses 
(sequence http://10.1.242.245:7778/acc ))))) not-registered)
at jade.domain.FIPAService.doFipaRequestClient(FIPAService.java:163)
at jade.domain.FIPAService.doFipaRequestClient(FIPAService.java:102)
at jade.domain.DFService.deregister(DFService.java:195)
at jade.domain.DFService.deregister(DFService.java:217)
at jade.domain.DFService.deregister(DFService.java:228)
at agenty.IntermediaryAgent.takeDown(IntermediaryAgent.java:43)
at jade.core.Agent.clean(Agent.java:1652)
at jade.core.Agent$ActiveLifeCycle.end(Agent.java:1567)
at jade.core.Agent.run(Agent.java:1495)
    at java.lang.Thread.run(Unknown Source)

I try use simple java class (not use agent) with jdbc code and it is works. When I use jdbc with agent it doesn't work. What is wrong?

Это было полезно?

Решение

You need the Oracle JDBC driver on your classpath.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top