entitybeanclienttest.java
来自「JAVA编程百例书中各章节的所有例子的源代码,包括套接字编程」· Java 代码 · 共 55 行
JAVA
55 行
package ch05.section09;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Enumeration;
import ch05.section08.*;
public class EntityBeanClientTest {
public static void main(String[] args) {
Account account = null;
try {
Context ctx = new InitialContext(System.getProperties());
AccountHome home = (AccountHome) ctx.lookup("AccountHome");
home.create("123-456-7890", "John Smith");
Enumeration e = home.findByOwnerName("John Smith");
if (e != null) {
account = (Account) e.nextElement();
}
else {
throw new Exception("Could not find account");
}
System.out.println("Initial Balance = " + account.getBalance());
account.deposit(100);
System.out.println("After depositing 100, account balance = " +
account.getBalance());
PKClass pk = (PKClass) account.getPrimaryKey();
account = null;
account = home.findByPrimaryKey(pk);
System.out.println("Found account with ID " + pk + ". Balance = " +
account.getBalance());
System.out.println("Now trying to withdraw $150, which is more than is currently available. This should generate an exception..");
account.withdraw(150);
}
catch (Exception e) {
System.out.println("Caught exception!");
e.printStackTrace();
}
finally {
try {
System.out.println("Destroying account..");
if (account != null) {
account.remove();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?