RMI - ClassNotFound for the Stub

Hi guys and thank you in advance for any help.
I have a simple RMI application. When I try to bind my remote object to the registry I am receiving an UnmarshallException caused by a ClassNotFoundException. My Stub.class and Skel.class are in the same directory as my implementation class.
I am relatively new to this stub. Can anyone shed any light on this?
Many thanks
Elliot

You may also look into setting the path to your stubs dynamically at the command prompt, with the -Djava.rmi.server.codebase=file:///<path_to_stubs>
or -Djava.rmi.server.codebase=c:\<path_to_stubs>
(for windows users)

Similar Messages

  • How to load classes other than stub classes required for the stub classes

    Can any one pls tell me how to load supporting classes and interfaces for the stubs thru RMI? I am copying necessary stubs and policy file in the client class.
    one of the method of the class returns another supporting class. whenever i invoke this method ot says Class NotFoundException. I dont want to copy these supporitng classes into my client. They are deployment issues involved with this.
    HOW CAN I LOAD THE CLEINT CLASSES THRU RMI

    You should look at the documentation concerning CODEBASE. -Djava.rmi.server.codebase=
    It is too involved to explain it all here.

  • RMI Timout for EJB Stubs

    I can get RMI timeouts working by manually adding timeout="N" to the
    XXX_EOImplRTD.xml file in the compiled EJB jar. For example:
    <rmi Name="ejb.XXX_EOImpl">
    <cluster clusterable="true" />
    <method name="*" timeout="500" />
    </rmi>
    Is there a way to set the timeout by passing a parameter to ejbc or
    adding a tag to the weblogic-ejb-jar.xml?
    Thanks,
    Bob

    I didn't find any
    Bob Lee <[email protected]> wrote:
    I can get RMI timeouts working by manually adding timeout="N" to the
    XXX_EOImplRTD.xml file in the compiled EJB jar. For example:
    <rmi Name="ejb.XXX_EOImpl">
    <cluster clusterable="true" />
    <method name="*" timeout="500" />
    </rmi>
    Is there a way to set the timeout by passing a parameter to ejbc or
    adding a tag to the weblogic-ejb-jar.xml?
    Thanks,
    Bob--
    Dimitri

  • RMI only for applets?

    I have spent couple of days trying to make my client/server application to work. I use RMI and both sides are ready and do execute, but I can't make the client receive the Stub file. All I get is a ClassNotFoundException telling me that the "myproject.server.MyImpl_Stub.class" can't be found. What confuses me is that it is searched from the server (Amongst the other server classes!?), but I don't seem to be able to change (or point) the location where it should be looked for...
    I just read that RMI is primarly for applets, and now I'm feeling a bit worried if I can't make my application work at all... This is (soon to be was) supposed to be my course project and I have worked pretty hard on this.
    I really hope that the problem is only with setting the codebase. If so, I hope someone could tell me how to point the right place* from the server for the RmiRegistry -> client. I have also noticed that RMIClassLoader class is somehow related to this topic. Should it be used somewhere? How?
    * If the path is for example: c:\java\my_project\server\ --> java.rmi.server.codebase=???
    I do really appreciate all the help and advice I can get. Thank you in advance!
    - Ville

    I have already read some tutorials. And I have understood that the client is the one which needs the stub(s), but the server is the one to provide it/them. Right? I'm not sure what you mean by starting the server separately with the stubs, but that is, what I think, I have done.
    I copied my server classes so that they where with client at corresponding place given by ClassNotFoundException. Now I got ClassCastException!? I think that this proves that the instance sent by rmiregistry is telling the client to ask for the stub from the wrong place.
    This is what I think how stubs are used and what they are...
    Server registers an remote object for rmiregistry with Naming.(re)bind(). Rmiregistry then gives an instance (of this objects stub) for the client when it does its Naming.lookup(). After that client requests the stub.class from given location (which is given by the servers codebase setting [only for applets??]), and then the stub.class is downloaded for the client. When this is done, the stub is used by the client to make calls for the servers remote object, to do what the client asks it to do (if allowed).
    Is this far from the truth?

  • The usual ClassNotFound for stubs, but I cant remember

    Hi guys. I have a problem with my rmi app. First of all
    I have the server stuff in server package, the worker stuff in worker package, some essential code in source package and thats it. So the directory structure is
    path/server, path/worker, path/source etc.
    Although in the office machines it works fine, in the house I get
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
         java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
         java.lang.ClassNotFoundException: server.ServerImpl_Stub
    but the stubs are there. I am in the root dir and doing javac server/*.java, javac worker/*.java etc
    then rmic server.ServerImpl
    and then java server/ServerStarter (server.ServerStarter doesnt make a difference)
    Can somebody please help because I need to do a lot of work during the weekend. thx

    This has been solved. The problem was that the stubs and main classes had to be compiled with the same Java version and rmiregistry started from the root project dir. thx

  • Not able to download all the stubs using the WSDL provided for Contact.

    Hi All,
    I am using wsdl2java to download stubs from the wsdl for contact using axis.
    But i am not able to download all the files from the wsdl.
    I am not able to see ListofContactData.java file in the stubs created,but i a can see in the that in wsdl.
    Anybody can help me in this issue.
    Thanks & Regards
    Amith B N

    Hi Guys..
    please post the solution clearly. I have the same problem and have to complete the development in short span..
    Please mates.. Hope u ppl will help on time.. if possible.. send me the document.
    refer my build.xml which i used for Version 1.0 in the below link.
    Re: wsdl v2.0 vs V1.0
    My mail id : [email protected]
    Regards
    Balaji Tr.

  • Geting "Incorrect client ID.The stub is not connected yet" during deploying

    Hai all,
          I am unable to deploy a J2EE application from Deploy Tool. The following trace is comg in defaultTrace.trc.2
    #1.5#000D9D9FAF62003C0000000900000F080003FC0472DB309D#1121520967258#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Guest#2##sap_J2E_1009250#Guest#097b3220f5fd11d9b557000d9d9faf62#Finalizer##0#0#Error#1#/System/Server#Plain#ID:Can't send inform message.: Incorrect client ID. The stub is not connected yet.#com.sap.engine.services.monitor.mbeans.MonitorResourceBundle##
    #1.5#000D9D9FAF62003C0000000A00000F080003FC0472DB33DE#1121520967258#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Guest#2##sap_J2E_1009250#Guest#097b3220f5fd11d9b557000d9d9faf62#Finalizer##0#0#Error#1#/System/Server#Plain###Incorrect client ID. The stub is not connected yet.#
    #1.5#000D9D9FAF62003C0000000B00000F080003FC0472DB3A15#1121520967258#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4.com.sap.engine.services.rmi_p4.StubImpl p4_finalize#Guest#2##sap_J2E_1009250#Guest#097b3220f5fd11d9b557000d9d9faf62#Finalizer##0#0#Error##Plain###
    com.sap.engine.services.rmi_p4.exception.P4BaseIOException: Incorrect client ID. The stub is not connected yet.
         at com.sap.engine.services.rmi_p4.server.P4ObjectBrokerServerImpl.getException(P4ObjectBrokerServerImpl.java:860)
         at com.sap.engine.services.rmi_p4.server.P4ObjectBrokerServerImpl.getException(P4ObjectBrokerServerImpl.java:853)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.reply(P4SessionProcessor.java:169)
         at com.sap.engine.services.rmi_p4.StubImpl.p4_finalize(StubImpl.java:221)
         at com.sap.engine.services.rmi_p4.StubBase.finalize(StubBase.java:121)
         at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
         at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
         at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
         at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
    #1.5#000D9D9FAF62003C0000000C00000F080003FC0472DB3F36#1121520967258#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Guest#2##sap_J2E_1009250#Guest#097b3220f5fd11d9b557000d9d9faf62#Finalizer##0#0#Error#1#/System/Server#Plain#ID:Can't send inform message.: Incorrect client ID. The stub is not connected yet.#com.sap.engine.services.monitor.mbeans.MonitorResourceBundle##
    #1.5#000D9D9FAF62003C0000000D00000F080003FC0472DB423D#1121520967258#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Guest#2##sap_J2E_1009250#Guest#097b3220f5fd11d9b557000d9d9faf62#Finalizer##0#0#Error#1#/System/Server#Plain###Incorrect client ID. The stub is not connected yet.#
    #1.5#000D9D9FAF62003C0000000E00000F080003FC0472DB47AA#1121520967258#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4.com.sap.engine.services.rmi_p4.StubImpl p4_finalize#Guest#2##sap_J2E_1009250#Guest#097b3220f5fd11d9b557000d9d9faf62#Finalizer##0#0#Error##Plain###
    com.sap.engine.services.rmi_p4.exception.P4BaseIOException: Incorrect client ID. The stub is not connected yet.
         at com.sap.engine.services.rmi_p4.server.P4ObjectBrokerServerImpl.getException(P4ObjectBrokerServerImpl.java:860)
         at com.sap.engine.services.rmi_p4.server.P4ObjectBrokerServerImpl.getException(P4ObjectBrokerServerImpl.java:853)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.reply(P4SessionProcessor.java:169)
         at com.sap.engine.services.rmi_p4.StubImpl.p4_finalize(StubImpl.java:221)
         at com.sap.engine.services.rmi_p4.StubBase.finalize(StubBase.java:121)
         at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
         at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
         at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
         at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
    #1.5#000D9D9FAF62003B0000000100000F080003FC047395DF47#1121520979492#com.sap.engine.compilation##com.sap.engine.compilation.ExternalCompiler.compile()#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngine_Application_Thread[impl:3]_32##0#0#Error##Plain###Error while compiling :
    java.io.IOException: CreateProcess: javac -encoding Cp1252 -d C:/usr/sap/J2E/JC00/j2ee/cluster/server0/apps/sap.com/onlyear/EJBContainer/temp/temp1121520967445 -classpath .;./bin/system/frame.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/jms/jms.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/tcsecssl/iaik_jsse.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/webservices_lib/saaj-api.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/tcsecssl/iaik_smime.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/add_ejb/add_ejb.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/servlet/servlet.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/services/naming/naming.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/webservices_lib/webservices_lib.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/interfaces/resourcecontext_api/resourcecontext_api.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/ext/tcsecssl/w3c_http.jar;C:/usr/sap/J2E/JC00/j2ee/cluster/server0/bin/interfaces/webservices/webservices_api.jar;C:/us?
         at java.lang.Win32Process.create(Native Method)
         at java.lang.Win32Process.<init>(Win32Process.java:66)
         at java.lang.Runtime.execInternal(Native Method)
         at java.lang.Runtime.exec(Runtime.java:566)
         at java.lang.Runtime.exec(Runtime.java:491)
         at java.lang.Runtime.exec(Runtime.java:457)
         at com.sap.engine.compilation.ExternalCompiler.compile(ExternalCompiler.java:65)
         at com.sap.engine.services.ejb.util.AdminUtils.compile(AdminUtils.java:449)
         at com.sap.engine.services.ejb.deploy.DeployAdmin.deploySingleJar(DeployAdmin.java:625)
         at com.sap.engine.services.ejb.deploy.DeployAdmin.generate(DeployAdmin.java:266)
         at com.sap.engine.services.ejb.EJBAdmin.deploy(EJBAdmin.java:2093)
         at com.sap.engine.services.deploy.server.application.DeploymentTransaction.makeComponents(DeploymentTransaction.java:1015)
         at com.sap.engine.services.deploy.server.application.DeploymentTransaction.begin(DeploymentTransaction.java:594)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhasesOnOneServer(ApplicationTransaction.java:300)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhases(ApplicationTransaction.java:331)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.makeGlobalTransaction(DeployServiceImpl.java:2910)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.deploy(DeployServiceImpl.java:451)
         at com.sap.engine.services.deploy.server.DeployServiceImplp4_Skel.dispatch(DeployServiceImplp4_Skel.java:1511)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:286)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:172)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:104)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:140)
    #1.5#000D9D9FAF62003B0000000900000F080003FC04739BCB45#1121520979883#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngine_Application_Thread[impl:3]_32##0#0#Error##Plain###com.sap.engine.services.rmi_p4.DispatchImpl _runInternal Cannot deploy application sap.com/onlyear..
    Reason: Exception during generation of components of application sap.com/onlyear in container EJBContainer.; nested exception is:
         com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Exception during generation of components of application sap.com/onlyear in container EJBContainer.#
    #1.5#000D9D9FAF62003B0000000A00000F080003FC04739BD41D#1121520979883#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4.com.sap.engine.services.rmi_p4.DispatchImpl runInternal#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngineApplication_Thread[impl:3]_32##0#0#Error##Plain###
    java.rmi.RemoteException: Cannot deploy application sap.com/onlyear..
    Reason: Exception during generation of components of application sap.com/onlyear in container EJBContainer.; nested exception is:
         com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Exception during generation of components of application sap.com/onlyear in container EJBContainer.
         at com.sap.engine.services.deploy.server.DeployServiceImpl.deploy(DeployServiceImpl.java:466)
         at com.sap.engine.services.deploy.server.DeployServiceImplp4_Skel.dispatch(DeployServiceImplp4_Skel.java:1511)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:286)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:172)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:104)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:140)
    Caused by: com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Exception during generation of components of application sap.com/onlyear in container EJBContainer.
         at com.sap.engine.services.deploy.server.application.DeploymentTransaction.makeComponents(DeploymentTransaction.java:1021)
         at com.sap.engine.services.deploy.server.application.DeploymentTransaction.begin(DeploymentTransaction.java:594)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhasesOnOneServer(ApplicationTransaction.java:300)
         at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhases(ApplicationTransaction.java:331)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.makeGlobalTransaction(DeployServiceImpl.java:2910)
         at com.sap.engine.services.deploy.server.DeployServiceImpl.deploy(DeployServiceImpl.java:451)
         ... 10 more
    Caused by: java.lang.NullPointerException
         at com.sap.engine.compilation.ExternalCompiler.getErrorMessage(ExternalCompiler.java:123)
         at com.sap.engine.services.ejb.util.AdminUtils.compile(AdminUtils.java:451)
         at com.sap.engine.services.ejb.deploy.DeployAdmin.deploySingleJar(DeployAdmin.java:625)
         at com.sap.engine.services.ejb.deploy.DeployAdmin.generate(DeployAdmin.java:266)
         at com.sap.engine.services.ejb.EJBAdmin.deploy(EJBAdmin.java:2093)
         at com.sap.engine.services.deploy.server.application.DeploymentTransaction.makeComponents(DeploymentTransaction.java:1015)
         ... 15 more
    #1.5#000D9D9FAF62003B0000000D00000F080003FC04739BDA8D#1121520979883#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngine_Application_Thread[impl:3]_32##0#0#Error#1#/System/Server#Plain#ID:011403: Cannot deploy application sap.com/onlyear..
    Reason: Exception during generation of components of application sap.com/onlyear in container EJBContainer.; nested exception is:
         com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Exception during generation of components of application sap.com/onlyear in container EJBContainer.#com.sap.engine.services.monitor.mbeans.MonitorResourceBundle##
    #1.5#000D9D9FAF62003B0000000E00000F080003FC04739BDCAE#1121520979883#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngine_Application_Thread[impl:3]_32##0#0#Error#1#/System/Server#Plain###Cannot deploy application sap.com/onlyear..
    Reason: Exception during generation of components of application sap.com/onlyear in container EJBContainer.; nested exception is:
         com.sap.engine.services.deploy.exceptions.ServerDeploymentException: Exception during generation of components of application sap.com/onlyear in container EJBContainer.#
    #1.5#000D9D9FAF62003B0000000F00000F080003FC04739BDEA3#1121520979883#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngine_Application_Thread[impl:3]_32##0#0#Error##Plain###TraceException in DispatchImpl...#
    #1.5#000D9D9FAF62003B0000001000000F080003FC04739BDFA7#1121520979883#com.sap.engine.services.rmi_p4##com.sap.engine.services.rmi_p4#Administrator#32###Administrator#8c8d9e90f5fe11d99d3d000d9d9faf62#SAPEngine_Application_Thread[impl:3]_32##0#0#Error##Plain###P4:SAPEngine_Application_Thread[impl:3]_32: TraceException in DispatchImpl...#
    The above trace repeating all the time when I try to deploy.
    Can any body tell whether is it a configuration problem or any application problem. Also on the same server another j2ee application is deploying successfully.
    Thanks a lot,
    Gangadhar.

    Hai,
        Thanks Brandelik, actually the problem was coming because of java.lang.outOfMemory exception during compilation time.
         As of now I am not able to fix that problem. I am changing all the available options for memory settings.
        Anybody please help me how to set the memory parameters for deploying an application. My application needs minimum of -Xmx512m for deployment on oracle10g server.
    Thanx,
    Gangadhar.

  • Where is the Stub created? In registry or in Client's machine?

    Hii..
    I hav some doubts abt RMI..
    The part after t client getting t remote ref(stub obj) of t client s perfectly clear 2 me.
    My doubt s abt t previous part � ie. How t client gets t stub obj.
    I ll tell my concept abt this� plzz correct me if I m wrong.. :
    Suppose Rmiregistry n server(which extends from UnicastRemoteObj)runs on t same m/c
    Client runs on another m/c
    1. Wen server s up, it exports itself 2 a particular port n listens 2 t port for incoming client connections.. (this port s chosen arbitrary@runtime)
    2. Rmiregistry listens 2 port 1099 on t same machine..
    3. Server registers a public name wit registry n pass t a Remote obj(server obj) as t second param in t bind/rebind call
    4. Rmiregistry itself s a remote object.. For accessing any remote object we need a stub.. t Naming class act as t stub for rmiregistry
    5. Now t situation s client needs 2 get an obj of stub 2 contact t server, or at least it shud know 2 which arbitrary port t server s listening 2
    6. so it looks up t rmiregistry for t public name, t rmiregistry creates an object of stub and returns t stub object 2 t client..(is it right?)
    7. For creating an obj of stub, rmiregistry must know 2 which port t server is listening(so t server might hav given t info 2 registry while binding.. right??)
    8. since rmiregistry itself is a remote object t newly created stub object itself is passed in a serialized manner(registry marshals t stub obj) 2 t client using t rmi protocol itself.
    9. now t client demarshalls t passed stub obj 2 get t stub
    10. finally t client uses t stub 2 directly communicate wit t server(ie. 2 connect 2 t listening port of t server)
    11. now t commn b/w client n server takes place directly without t intervention of t rmiregistry�
    This s my Concept abt t whole scenario in 1.4(in 1.5 no need 4 stub or skeletons) plzz correct me if I m wrong@any of these points..
    If my concept is right, then I hav a few q�
    Consider an application Calc
    � remote interface : Calc(which extends Remote)
    � server which implements t Calc i/f : CalcImlp(which extends UnicastRemoteObject)
    � client : CalcClient
    In CalcImpl�s main(),
    Naming.bind(�calc�, new CalcImpl())
    In CalcClient,
    Remote r=(Calc)Naming.lookup(�rmi://host:1099/calc�);
    My doubt is that t server s passing an obj of CalcImpl 2 t registry in Bind fn and wat t client s getting wit lookup fn s actually an obj of CalcImp_Stub which t rmic generated. So does t rmiregistry uses Reflection 2 get t name of CalcImpl n then add a �_Stub� 2 t name it got and searches for that class??
    I hav been checking so many books 2 check whether my concept s right or wrong..
    But I didn�t any info from anywhere.. all of those docs say how 2 do it� None of them say what s happening inside�
    Plzz help me...

    Please don't use this sort of SMS speak "thnx 2 u" when asking a question. If you haven't sufficient respect to spell it all out, why should we make the effort to reply?
    I've not tried to read through all that butchered English, but in brief:
    Stubs can be created at compile time, or with Java 5 they can be dynamically created on the client in communication with the server.
    In the former case, they can either be distributed with the client application or downloaded from a specific URL. It is up to you to specify the URL and make it available. It is not the job of the registry.
    In the latter case you won't need to do anything special.
    If you want a good book which covers this in detail, I recommend the William Grosso RMI book. This is pre-Java 5, but covers the internals of the RMI mechanism in a lot of detail. Hopefully a new edition will be issued to cover Java 5.
    Dave.

  • The service cannot be found for the endpoint reference (EPR) 127.0.0.1/a

    Hi All:
    I need help!!!
    I am using axis2-1.5.1, jdk 1.6, eclipse 3.5, and Axis2_Codegen_Wizard_1.3.0 and windows xp.
    I used Axis2_Codegen_Wizard_1.3.0 to generate the client stub and proxy.
    I get the following error when I tried to call the web service:
    package com.ttdev.ss.client;
    import java.rmi.RemoteException;
    import com.ttdev.ss.client.SimpleServiceStub.ConcatRequest;
    import com.ttdev.ss.client.SimpleServiceStub.ConcatResponse;
    public class SimpleClient
         public static void main(String[] args) throws RemoteException
              try
              SimpleServiceStub service = new SimpleServiceStub();
              ConcatRequest request = new ConcatRequest();
              request.setS1("abc");
              request.setS2("123");
              ConcatResponse response = service.concat(request);
              System.out.println(response.getConcatResponse());
              catch(Exception e)
                   System.out.println("e.getMessage():"+e.getMessage());
    Here is my SimpleService.wsdl:
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions name="SimpleService" targetNamespace="http://ttdev.com/ss" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ttdev.com/ss" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <wsdl:types>
    <xsd:schema targetNamespace="http://ttdev.com/ss">
    <xsd:element name="concatRequest">
    <xsd:complexType>
    <xsd:sequence>
         <xsd:element name="s1" type="xsd:string"/>
         <xsd:element name="s2" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="concatResponse" type="xsd:string">
    </xsd:element>
    </xsd:schema>
    </wsdl:types>
    <wsdl:message name="concatResponse">
    <wsdl:part name="parameters" element="tns:concatResponse">
    </wsdl:part>
    </wsdl:message>
    <wsdl:message name="concatRequest">
    <wsdl:part name="parameters" element="tns:concatRequest">
    </wsdl:part>
    </wsdl:message>
    <wsdl:portType name="SimpleService">
    <wsdl:operation name="concat">
    <wsdl:input message="tns:concatRequest">
    </wsdl:input>
    <wsdl:output message="tns:concatResponse">
    </wsdl:output>
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="SimpleServiceSOAP" type="tns:SimpleService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="concat">
    <soap:operation soapAction="http://ttdev.com/ss/NewOperation"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="SimpleService">
    <wsdl:port name="SimpleServiceSOAP" binding="tns:SimpleServiceSOAP">
    <soap:address location="http://localhost:8080/axis2/services/"/>
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>
    In the dos-prompt, I get the following error message:
    [INFO] Listening on port 8080
    [ERROR] The service cannot be found for the endpoint reference (EPR) 127.0.0.1/a
    xis2/services/
    org.apache.axis2.AxisFault: The service cannot be found for the endpoint referen
    ce (EPR) 127.0.0.1/axis2/services/
    at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPha
    se.java:65)
    at org.apache.axis2.engine.Phase.invoke(Phase.java:334)
    at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:251)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:160)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostReq
    uest(HTTPTransportUtils.java:167)
    at org.apache.axis2.transport.http.HTTPWorker.service(HTTPWorker.java:26
    6)
    at org.apache.axis2.transport.http.server.AxisHttpService.doService(Axis
    HttpService.java:281)
    at org.apache.axis2.transport.http.server.AxisHttpService.handleRequest(
    AxisHttpService.java:187)
    at org.apache.axis2.transport.http.server.HttpServiceProcessor.run(HttpS
    erviceProcessor.java:82)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
    utor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:908)
    at java.lang.Thread.run(Thread.java:619)
    Thank you for your help!!!
    Yours,
    John.

    I had the same issue and managed to fix it.
    I am using tomcat and had a filter configured for AxisServlet to open a hibernate Session. Somehow (I did not figure it out yet) this filter afects the way the AxisServlet resolves the EPR.
    My fix was - remove the filter. It worked. Now I am trying to figure out why.
    If you have any clues, please drop a line.

  • RMI - What's the point?

    I'm having a hard time understanding the reasons for using RMI. The client needs the remote server classes locally anyway in the classpath so why bother calling the remote classes? Is it the fact that you don't need all the remote classes locally, only the ones that you reference in you client side code?

    I'm having a hard time understanding the reasons for
    using RMI. The client needs the remote server classes
    locally anyway in the classpath so why bother calling
    the remote classes? Is it the fact that you don't need
    all the remote classes locally, only the ones that you
    reference in you client side code?First of all, you can't call a class. I don't really even know
    what you mean by that. The point of RMI is to call methods of
    a remote object. The class that implements that object
    does not need to be available on the client side. The client
    side just has a stub to represent the remote object. Even if
    the implementing class exists on both client and server, the
    object the client wants to access only exists on the server.
    That is what RMI is for.

  • RMI SERVER behind the router....!!!!!!!!!!!!

    Hi I am new here...And Have a problem regarding to java RMI...
    I have a uni assignment which asks us to write an online tic tac toe game using RMI..well assigment only request if it can be run on the same machine and I finished..
    But now I am trying to config it to real life with internet instead of LAN.
    Basically I have one static IP assigned by my ISP... and I have local IP addresses on my machines. The addresses will be translated by my router to the public one...
    My server is running on port 8081 of my server computer with an local IP addresses... and I did port forwarding in my router to forward all the 8081 request to this server...
    And the the client use the public IP to locate my server they can acctually connect to my server and get the stub or ref to it...But when they acctually trying to call a method on
    the server side, I realised they actually using the local IP addresses of my server machine instead of the public one..so i think the stub acctually bind the machine IP and ask client to use this IP to communicate.
    This obviously not going to work...And In the API it seems like I can not acctually do anything about IP address when create the Registry..
    Any clue on this Thank you.......

    No, the stub consists of a single Java object which contains the IP address and port number of the host from which the remote object was exported. The client knows the initial lookup address for the Registry but it performs all subsequent communications via the information embedded in the stub.
    @OP: you need to export your remote object on a fixed port, have the router forward that port, and set the system property java.rmi.server.hostname in the server JVM to the external IP address of the router.

  • RMI only for applets?3F

    I have spent couple of days trying to make my client/server application to work. I use RMI and both sides are ready and do execute, but I can't make the client receive the Stub file. All I get is a ClassNotFoundException telling me that the "myproject.server.MyImpl_Stub.class" can't be found. What confuses me is that it is searched from the server (Amongst the other server classes!?), but I don't seem to be able to change (or point) the location where it should be looked for...
    I just read that RMI is primarly for applets, and now I'm feeling a bit worried if I can't make my application work at all... This is (soon to be was) supposed to be my course project and I have worked pretty hard on this.
    I really hope that the problem is only with setting the codebase. If so, I hope someone could tell me how to point the right place* from the server for the RmiRegistry -> client. I have also noticed that RMIClassLoader class is somehow related to this topic. Should it be used somewhere? How?
    * If the path is for example: c:\java\my_project\server\
    I do really appreciate all the help and advice I can get. Thank you in advance!
    - Ville
    do really appreciate all the help and advice I can get. Thank you in advance!
    - Ville

    Dude, why are you just copying other people's posts?

  • RMI: Ensuring that classes/stubs are NOT dynamically downloaded.

    This is for my SCJD exam, which states, "You must provide all classes pre-installed so that no dynamic class downloading occurs."
    Due to my lack of experience with RMI, I decided to write a small test program to get comfortable with the technology. I would like to confirm that my RMI example does not use any "dynamic class downloading."
    My example program consists of three classes: DateService (an interface that extends Remote); DateServiceImpl (an implementation of DateService, which contains the code to create an RMI registry, export a DateService implementation instance, and bind it to the registry); and DateClient, which looks for the RMI registry, finds the DateService object, and calls one of its methods.
    I have used rmic to generate a DateServiceImpl_Stub.class file. I have left this file in the same directory as DateServiceImpl.class.
    Does it sound as if I have got this correct? I will post my code in the next post.
    Thanks in advance.

    DateService.javapackage date;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface DateService extends Remote {
         * Returns an array containing data pertaining to the current date.
         * The first index of the array contains the year, the second has
         * the month, and the third contains the day.
         * @return  the current date in an array, separated into year, month, and day
         * @throws  RemoteException if the remote invocation fails
        public String[] currentDate() throws RemoteException;
    DateServiceImpl.javapackage server;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.rmi.server.UnicastRemoteObject;
    import java.util.Calendar;
    import date.DateService;
    public class DateServiceImpl implements DateService {
         * Returns an array containing data pertaining to the current date.
         * The first index of the array contains the year, the second has
         * the month, and the third contains the day.
         * @return  the current date in an array, separated into year, month, and day
         * @throws  RemoteException if the remote invocation fails
        public String[] currentDate() throws RemoteException {
            String[] ymd = new String[3];
            Calendar today = Calendar.getInstance();
            ymd[0] = Integer.toString(today.get(Calendar.YEAR));
            ymd[1] = Integer.toString(today.get(Calendar.MONTH) + 1);
            ymd[2] = Integer.toString(today.get(Calendar.DATE));
            for (int i = 0; i < ymd.length; i++) {
                if (ymd.length() < 2) {
    ymd[i] = "0" + ymd[i];
    return ymd;
    public static void main(String[] args) {
    try {
    String name = "DateService";
    int rmiPort = 1099;
    DateService service = new DateServiceImpl();
    System.out.println("DateServiceImpl instance created.");
    Registry registry = LocateRegistry.createRegistry(rmiPort);
    System.out.println("RMI registry created on port " + rmiPort);
    DateService stub =
    (DateService)UnicastRemoteObject.exportObject(service, 0);
    System.out.println(
    "Service object exported and able to receive method invocation calls.");
    registry.rebind(name, stub);
    System.out.println("DateServiceImpl bound to the name \"" + name + "\"");
    while (true) {
    try {
    Thread.sleep(100);
    } catch (InterruptedException e) {
    e.printStackTrace();
    } catch (Exception e) {
    System.err.println("DateServiceImpl exception:");
    e.printStackTrace();
    DateClient.javapackage client;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import date.DateService;
    public class DateClient {
        public static void main(String args[]) {
            try {
                String name = "DateService";
                Registry registry = LocateRegistry.getRegistry();
                DateService service = (DateService)registry.lookup(name);
                String[] today = service.currentDate();
                for (int i = 0; i < today.length; i++) {
                    System.out.print((i == 0 ? "Today's date is " : "/") + today);
    System.out.println();
    } catch (Exception e) {
    System.err.println("DateClient exception:");
    e.printStackTrace();

  • Type-mapping not working correctly, get "Unable to find a javaType for the xmlType" WARNING

    I'm manually creating a web-services.xml file, and using the autogen ant task to
    generate the codec XML/Java classes. The XML definition is provided by SAP.
    The ant build.xml file:
    <project name="buildWebservice" default="stubgen">
    <target name="stubgen">
    <clientgen ear="C:\projects\RMIS\ifrrequests\RMIS.ear"
    packageName="com.aa.rmis.webservice.client"
    clientJar="C:\projects\RMIS\ifrrequests\rmisws-client.jar"
    autotype="False" />
    </target>
    <target name="all" depends="stubgen"/>
    </project>
    The problem is seen below in the output from Ant. Note the WARNINIG. The problem
    is that the xml type cannot be mapped to the Java type.
    C:\projects\RMIS\ifrrequests>ant -buildfile clientbuild.xml
    Buildfile: clientbuild.xml
    stubgen:
    [clientgen] Generating client jar for RMIS.ear ...
    [clientgen] WARNINIG: Unable to find a javaType for the xmlType:['urn:sap-com:do
    cument:sap:business']:PaymentRequest.Create. Make sure that you have registered
    this xml type in the type mapping
    [clientgen] Using SOAPElement instead
    [clientgen] Compiling 4 source files to C:\DOCUME~1\944377\LOCALS~1\Temp\rmisws-
    client.jar-836624340
    [clientgen] Building jar: C:\projects\RMIS\ifrrequests\rmisws-client.jar
    BUILD SUCCESSFUL
    Total time: 17 seconds
    The Java source that has the implementation of the service methods is simply:
    package com.aa.rmis.webservice;
    import com.aa.rmis.ifr.request.*;
    public class TestService
    public TestService()
    public int serviceRequest(PaymentRequestCreate request)
    System.out.println("Received serviceRequest message");
    return 0;
    public void testStringRequest(String request)
    The web-service.xml file is attached, which contains the schema for the SAP PaymentRequest.Create
    object definition.
    Another problem I have, which is probably related, is that the service method
    that has a complex data type (non-built in data type) is not being deployed into
    the WebLogic server. But the other service method that simply takes a String
    parameter is.
    The steps I took are:
    1. Get XML from SAP Interface Repository (IFR) for PaymentRequest
    2. Use ant task autogen to generate the request codec classes
    3. Create the web-services.xml file by inserting the schema definition and the
    mapping file created by the autogen task, and defining the operations
    4. Build web-services.war file that contains all autogen compiled class files,
    the web-services.xml file, and the service implementation class
    5. Build the ear file that holds the web service files
    6. Use the clientgen ant task to generate (included above) to generate the client
    jar file that should contain the proxy for both of the service methods
    Environment:
    * WebLogic 7.02
    * JDK 1.3.1_06
    * JBuilder 9 Enterprise
    * Ant 1.4
    Possible causes:
    * Namespace not being used correctly
    * copied verbatim the mapping xml file generated by autogen into the web-services.xml
    file
    * xml-schema part of web-services.xml might not be set correctly
    * operation definition might not be using the correct namespace
    * Classpath used for ant might not be right
    * Doubt this is the problem, but I'm out of other ideas
    * Set by using the setWLEnv.cmd file provided by WebLogic
    * Tried adding the generated classes directory for my project to the classpath,
    but did not work
    I've been referencing the Programming WebLogic Web Services document throughout
    this entire process. I must be missing something.
    Can anybody from BEA help me out with this problem?
    Thanks in advance.
    [web-services.xml]

    Hi JD,
    I spent a few cycles looking over your web-services.xml file, however I
    don't have any suggestions other that one that looks like you have
    already tried, at the top, in the <schema...>
    targetNamespace="urn:sap-com:document:sap:business"
    Making edits to these generated files can be tricky and my only
    suggestion is to create a small reproducer to run by our outstanding
    support team.
    A quick look at our problem database shows one issue (CR095109) related
    to a similar problem at deploy time that was fixed with 7.0SP3. Again,
    the support folks will be able to help focus in on the issue.
    Regards,
    Bruce
    JD wrote:
    >
    The first posting contains the wrong web-services.xml file. Please refer to this
    one instead.
    "JD" <[email protected]> wrote:
    I'm manually creating a web-services.xml file, and using the autogen
    ant task to
    generate the codec XML/Java classes. The XML definition is provided
    by SAP.
    The ant build.xml file:
    <project name="buildWebservice" default="stubgen">
    <target name="stubgen">
    <clientgen ear="C:\projects\RMIS\ifrrequests\RMIS.ear"
    packageName="com.aa.rmis.webservice.client"
    clientJar="C:\projects\RMIS\ifrrequests\rmisws-client.jar"
    autotype="False" />
    </target>
    <target name="all" depends="stubgen"/>
    </project>
    The problem is seen below in the output from Ant. Note the WARNINIG.
    The problem
    is that the xml type cannot be mapped to the Java type.
    C:\projects\RMIS\ifrrequests>ant -buildfile clientbuild.xml
    Buildfile: clientbuild.xml
    stubgen:
    [clientgen] Generating client jar for RMIS.ear ...
    [clientgen] WARNINIG: Unable to find a javaType for the xmlType:['urn:sap-com:do
    cument:sap:business']:PaymentRequest.Create. Make sure that you have
    registered
    this xml type in the type mapping
    [clientgen] Using SOAPElement instead
    [clientgen] Compiling 4 source files to C:\DOCUME~1\944377\LOCALS~1\Temp\rmisws-
    client.jar-836624340
    [clientgen] Building jar: C:\projects\RMIS\ifrrequests\rmisws-client.jar
    BUILD SUCCESSFUL
    Total time: 17 seconds
    The Java source that has the implementation of the service methods is
    simply:
    package com.aa.rmis.webservice;
    import com.aa.rmis.ifr.request.*;
    public class TestService
    public TestService()
    public int serviceRequest(PaymentRequestCreate request)
    System.out.println("Received serviceRequest message");
    return 0;
    public void testStringRequest(String request)
    The web-service.xml file is attached, which contains the schema for the
    SAP PaymentRequest.Create
    object definition.
    Another problem I have, which is probably related, is that the service
    method
    that has a complex data type (non-built in data type) is not being deployed
    into
    the WebLogic server. But the other service method that simply takes
    a String
    parameter is.
    The steps I took are:
    1. Get XML from SAP Interface Repository (IFR) for PaymentRequest
    2. Use ant task autogen to generate the request codec classes
    3. Create the web-services.xml file by inserting the schema definition
    and the
    mapping file created by the autogen task, and defining the operations
    4. Build web-services.war file that contains all autogen compiled class
    files,
    the web-services.xml file, and the service implementation class
    5. Build the ear file that holds the web service files
    6. Use the clientgen ant task to generate (included above) to generate
    the client
    jar file that should contain the proxy for both of the service methods
    Environment:
    * WebLogic 7.02
    * JDK 1.3.1_06
    * JBuilder 9 Enterprise
    * Ant 1.4
    Possible causes:
    * Namespace not being used correctly
    * copied verbatim the mapping xml file generated by autogen into
    the web-services.xml
    file
    * xml-schema part of web-services.xml might not be set correctly
    * operation definition might not be using the correct namespace
    * Classpath used for ant might not be right
    * Doubt this is the problem, but I'm out of other ideas
    * Set by using the setWLEnv.cmd file provided by WebLogic
    * Tried adding the generated classes directory for my project to
    the classpath,
    but did not work
    I've been referencing the Programming WebLogic Web Services document
    throughout
    this entire process. I must be missing something.
    Can anybody from BEA help me out with this problem?
    Thanks in advance.
    Name: web-services.xml
    web-services.xml Type: ACT Project (text/xml)
    Encoding: base64

  • Getting Connected for the First Time with JDBC

    Hello everyone. I am trying to make my first database connection to a mysql database with Java. I am using jdk 1.5.0, MySQL 4.1.11 nt, and I think I have the freshly downloaded driver C:\jdk1.5.0\jre\lib\ext\mysql-connector-java-3.0.16-ga-bin.jar" installed in the right spot. When I try to run the following code...
    package dbfinder;
    import java.sql.*;
    import javax.sql.*;
    import com.sun.rowset.JdbcRowSetImpl;
    import javax.sql.rowset.JdbcRowSet;
    import java.sql.ResultSetMetaData;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2005</p>
    * <p>Company: </p>
    * @author not attributable
    * @version 1.0
    public class DatabaseConnector {
    public DatabaseConnector() {
    public static void main(String args[]){
    Connection connection;
    Statement statement;
    // ResultSet resultSet;
    // ResultSetMetaData metaData;
    String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
    String DATABASE_URL = "jdbc:mysql://localhost/state_crime";
    String USER = "cis695d";
    String PASSWORD = "cis695d";
    JdbcRowSet rowSet = new JdbcRowSetImpl();
    try {
    Class.forName(DATABASE_DRIVER); // load database driver
    System.out.println("class loaded");
    rowSet.setUrl("DATABASE_URL");
    rowSet.setUsername(USER);
    rowSet.setPassword(PASSWORD);
    rowSet.setCommand("Select * FROM state_crime_rates");
    rowSet.execute();
    ResultSetMetaData metaData = rowSet.getMetaData();
    int numberOfColumns;
    numberOfColumns = metaData.getColumnCount();
    System.out.println(numberOfColumns);
    } catch(SQLException sqlException){
    sqlException.printStackTrace();
    System.exit(1);
    catch(ClassNotFoundException classNotFound){
    classNotFound.printStackTrace();
    System.exit(1);
    I get the following exception...
    java.sql.SQLException: No suitable driver
         at java.sql.DriverManager.getConnection(DriverManager.java:545)
         at java.sql.DriverManager.getConnection(DriverManager.java:171)
         at com.sun.rowset.JdbcRowSetImpl.connect(JdbcRowSetImpl.java:618)
         at com.sun.rowset.JdbcRowSetImpl.prepare(JdbcRowSetImpl.java:630)
         at com.sun.rowset.JdbcRowSetImpl.execute(JdbcRowSetImpl.java:526)
         at dbfinder.DatabaseConnector.main(DatabaseConnector.java:44)
    Does anyone have any ideas? Is it my code? Is there a different driver I should use? Any help would be greatly appreciated.

    Hello everyone. I am trying to make my first
    database connection to a mysql database with Java. I
    am using jdk 1.5.0, MySQL 4.1.11 nt, and I think I
    have the freshly downloaded driver
    C:\jdk1.5.0\jre\lib\ext\mysql-connector-java-3.0.16-ga
    -bin.jar" installed in the right spot. You shouldn't be putting that JAR in jre/lib/ext, even if you've found some docs to tell you to do it. Only language extensions (e.g., packages that begin w/javax) belong there.
    I get the following exception...
    java.sql.SQLException: No suitable driver
    Does anyone have any ideas? Is it my code? Is there
    a different driver I should use? Any help would be
    greatly appreciated.The driver is correct. The class loader found it, even though I think you should use the -classpath option to find the JAR.
    It's your code.
    What are you doing with all that RowSet stuff?
    This works. Study it:
    import java.sql.*;
    import java.util.*;
    * Command line app that allows a user to connect with a database and
    * execute any valid SQL against it
    public class DataConnection
        public static final String DEFAULT_DRIVER   = "sun.jdbc.odbc.JdbcOdbcDriver";
        public static final String DEFAULT_URL      = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Edu\\Java\\Forum\\DataConnection.mdb";
        public static final String DEFAULT_USERNAME = "admin";
        public static final String DEFAULT_PASSWORD = "";
        public static final String DEFAULT_DRIVER   = "com.mysql.jdbc.Driver";
        public static final String DEFAULT_URL      = "jdbc:mysql://localhost:3306/hibernate";
        public static final String DEFAULT_USERNAME = "admin";
        public static final String DEFAULT_PASSWORD = "";
        /** Database connection */
        private Connection connection;
         * Driver for the DataConnection
         * @param command line arguments
         * <ol start='0'>
         * <li>SQL query string</li>
         * <li>JDBC driver class</li>
         * <li>database URL</li>
         * <li>username</li>
         * <li>password</li>
         * </ol>
        public static void main(String [] args)
            DataConnection db = null;
            try
                if (args.length > 0)
                    String sql      = args[0];
                    String driver   = ((args.length > 1) ? args[1] : DEFAULT_DRIVER);
                    String url      = ((args.length > 2) ? args[2] : DEFAULT_URL);
                    String username = ((args.length > 3) ? args[3] : DEFAULT_USERNAME);
                    String password = ((args.length > 4) ? args[4] : DEFAULT_PASSWORD);
                    System.out.println("sql     : " + sql);
                    System.out.println("driver  : " + driver);
                    System.out.println("url     : " + url);
                    System.out.println("username: " + username);
                    System.out.println("password: " + password);
                    db = new DataConnection(driver, url, username, password);
                    System.out.println("Connection established");
                    Object result = db.executeSQL(sql);
                    System.out.println(result);
                else
                    System.out.println("Usage: db.DataConnection <sql> <driver> <url> <username> <password>");
            catch (SQLException e)
                System.err.println("SQL error: " + e.getErrorCode());
                System.err.println("SQL state: " + e.getSQLState());
                e.printStackTrace(System.err);
            catch (Exception e)
                e.printStackTrace(System.err);
            finally
                if (db != null)
                    db.close();
                db = null;
         * Create a DataConnection
         * @throws SQLException if the database connection fails
         * @throws ClassNotFoundException if the driver class can't be loaded
        public DataConnection() throws SQLException,ClassNotFoundException
            this(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
         * Create a DataConnection
         * @throws SQLException if the database connection fails
         * @throws ClassNotFoundException if the driver class can't be loaded
        public DataConnection(final String driver,
                              final String url,
                              final String username,
                              final String password)
            throws SQLException,ClassNotFoundException
            Class.forName(driver);
            this.connection = DriverManager.getConnection(url, username, password);
         * Get Driver properties
         * @param database URL
         * @return list of driver properties
         * @throws SQLException if the query fails
        public List getDriverProperties(final String url)
            throws SQLException
            List driverProperties   = new ArrayList();
            Driver driver           = DriverManager.getDriver(url);
            if (driver != null)
                DriverPropertyInfo[] info = driver.getPropertyInfo(url, null);
                if (info != null)
                    driverProperties    = Arrays.asList(info);
            return driverProperties;
         * Clean up the connection
        public void close()
            close(this.connection);
         * Execute ANY SQL statement
         * @param SQL statement to execute
         * @returns list of row values if a ResultSet is returned,
         * OR an altered row count object if not
         * @throws SQLException if the query fails
        public Object executeSQL(final String sql) throws SQLException
            Object returnValue;
            Statement statement = null;
            ResultSet rs = null;
            try
                statement = this.connection.createStatement();
                boolean hasResultSet    = statement.execute(sql);
                if (hasResultSet)
                    rs                      = statement.getResultSet();
                    ResultSetMetaData meta  = rs.getMetaData();
                    int numColumns          = meta.getColumnCount();
                    List rows               = new ArrayList();
                    while (rs.next())
                        Map thisRow = new LinkedHashMap();
                        for (int i = 1; i <= numColumns; ++i)
                            String columnName   = meta.getColumnName(i);
                            Object value        = rs.getObject(columnName);
                            thisRow.put(columnName, value);
                        rows.add(thisRow);
                    returnValue = rows;
            else
                int updateCount = statement.getUpdateCount();
                returnValue     = new Integer(updateCount);
            finally
                close(rs);
                close(statement);
            return returnValue;
         * Close a database connection
         * @param connection to close
        public static final void close(Connection connection)
            try
                if (connection != null)
                    connection.close();
                    connection = null;
            catch (SQLException e)
                e.printStackTrace();
         * Close a statement
         * @param statement to close
        public static final void close(Statement statement)
            try
                if (statement != null)
                    statement.close();
                    statement = null;
            catch (SQLException e)
                e.printStackTrace();
         * Close a result set
         * @param rs to close
        public static final void close(ResultSet rs)
            try
                if (rs != null)
                    rs.close();
                    rs = null;
            catch (SQLException e)
                e.printStackTrace();
         * Close a database connection and statement
         * @param connection to close
         * @param statement to close
        public static final void close(Connection connection, Statement statement)
            close(statement);
            close(connection);
         * Close a database connection, statement, and result set
         * @param connection to close
         * @param statement to close
         * @param rs to close
        public static final void close(Connection connection,
                                       Statement statement,
                                       ResultSet rs)
            close(rs);
            close(statement);
            close(connection);
    }%

Maybe you are looking for