return vResult;
}
public Vector getColumnName(){
return vColumnName;
}
public int getUpdateResult(){
return iReturn;
}
/*
public void ejbCreate(){
System.out.println("ejbCreate()");
}
public void ejbCreate(String sqlContext){
ejbCreate(sqlContext,null);
System.out.println("ejbCreate()");
}
*/
public void ejbCreate(String sqlContext,String[] paraValue) {
this.sqlContext = sqlContext;
this.paraValue = paraValue;
System.out.println("ejbCreate()");
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
sessionContext = context;
}
}
hello. HelloWorldHome文件(定义Home接口)如下所示:
package hello;
import java.rmi.*;
import javax.ejb.*;
public interface HelloWorldHome extends EJBHome{
public HelloWorld create(String sqlContext,String[] paraValue) throws RemoteException, CreateException;
}
Jbuilder6.0+Weblogic6.0完成EJB开发部署(5)
时间:2010-12-06
客户端测试程序:
package hello;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import java.sql.*;
public class HelloWorldBeanClient1 {
private static HelloWorldHome helloWorldHome = null;
private static HelloWorld hello = null;
static{
Context ctx = null;
Hashtable ht = new Hashtable();
System.out.println("Initializing bean access.");
try{
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx = new InitialContext(ht);
//look up jndi name
Object ref = ctx.lookup("testBean");
//cast to Home interface
helloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(ref, HelloWorldHome.class);
System.out.println("Get the ejbHome.");
String[] paraValue = new String[]{"16"};
hello=helloWorldHome.create("hello.testSQL",paraValue);
}catch(Exception e){System.out.println("cannot get the ejbBean!"+e);}
}
public HelloWorldBeanClient1() {
Vector vInnerValue;
try {
//hello.setParaValue(value);
//hello.setSqlContext("hello.testSQL");
hello.execute();
Vector columnName = hello.getColumnName();
Vector result = hello.getQueryResult();
for(int i=0;i {
vInnerValue = (Vector)result.elementAt(i);
for(int j=0;j {
System.out.print(columnName.elementAt(j)+" = ");
System.out.println(vInnerValue.elementAt(j));
}
}
//System.out.println("execute Result = "+hello.getUpdateResult());
}catch(Exception e) {
System.out.println("Failed initializing bean access.");
e.printStackTrace();
}
}
/**Main method*/
public static void main(String[] args) {
HelloWorldBeanClient1 client = new HelloWorldBeanClient1();
}
}
}
|