2012-05-24 64 views
0

我試圖用玉的Java和JDBCJava的玉石連接到數據庫

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

} 

連接到DATABSE但我得到錯誤

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 [email protected] 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 
[email protected]:1099/JADE :addresses (sequence http://10.1.242.245:7778/acc)) (deregister 
(df-agent-description :name (agent-identifier :name [email protected]: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) 

我嘗試用簡單的Java類(不使用代理)與jdbc代碼,它是作品。當我與代理使用jdbc時,它不起作用。哪裏不對?

+1

它只是說'java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver' –

回答

1

您需要類路徑上的Oracle JDBC驅動程序。

+0

rrrr ...你說得對。我的錯。非常感謝。 – Texicans

+0

@Texicans請接受/ upvote的答案,當你有機會:) – AHungerArtist