weblogic/jboss使用ejb3.0远程调用

package com.tudou.test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Properties; import java.util.TimeZone; import javax.naming.Context; import javax.naming.InitialContext; import org.junit.BeforeClass; import org.junit.Test; import com.tudou.t1Test.Classes; import com.tudou.t1Test.Student; import com.tudou.t1Test.StudentDao; public class TestStu { private static StudentDao studentDao; @BeforeClass public static void setUpBeforeClass() throws Exception { Properties p = new Properties(); // weblogic值为weblogic.jndi.WLInitialContextFactory // JBOSS为org.jnp.interfaces.NamingContextFactory p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); // Weblogic为 t3://localhost:7001 p.setProperty(Context.PROVIDER_URL, "localhost"); InitialContext init = new InitialContext(p); // weblogic为LoginBean#后面是实现类的全路径,包括包名 // 此时接口中必须配置为:@Stateless(mappedName="LoginBean") studentDao = (StudentDao) init.lookup("StudentDaoBean/remote"); } @Test public void loginTest() { TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); sdf.setTimeZone(timeZone); String times = sdf.format(new Date()); Classes c1 = new Classes(); c1.setClassName("1班"); Classes c2 = new Classes(); c2.setClassName("2班"); Classes c3 = new Classes(); c3.setClassName("3班"); Student s1 = new Student(c1, "scce005", "tudou", times); Student s2 = new Student(c1, "scce002", "doudou", times); Student s3 = new Student(c2, "scce003", "qq", times); Student s4 = new Student(c3, "scce004", "yaerfeng", times); boolean flag1 = studentDao.addStu(s1); boolean flag2 = studentDao.addStu(s2); boolean flag3 = studentDao.addStu(s3); boolean flag4 = studentDao.addStu(s4); if (flag1 == true) { System.out.println("用户1添加成功!!!"); } else { System.out.println("添加失败!!!"); } if (flag2 == true) { System.out.println("用户2添加成功!!!"); } else { System.out.println("添加失败!!!"); } if (flag3 == true) { System.out.println("用户3添加成功!!!"); } else { System.out.println("添加失败!!!"); } if (flag4 == true) { System.out.println("用户4添加成功!!!"); } else { System.out.println("添加失败!!!"); } List<Student> lists = studentDao.queryStudents(); if (lists != null) { System.out.println("学号\t\t玫级\t\t姓名\t\t入学日期"); for (Student s : lists) { System.out.println(s.getStuNo() + "\t" + s.getClasses().getClassName() + "\t" + s.getStuName() + "\t\t" + s.getCreateDate()); } } else { System.out.println("里面是空的"); } } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值