Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Writing Enterprise Applications with Java™ 2 SDK, Enterprise Edition phần 10 ppt
MIỄN PHÍ
Số trang
11
Kích thước
41.4 KB
Định dạng
PDF
Lượt xem
1232

Writing Enterprise Applications with Java™ 2 SDK, Enterprise Edition phần 10 ppt

Nội dung xem thử

Mô tả chi tiết

LESSON 7 JDBC TECHNOLOGY AND BEAN-MANAGED PERSISTENCE

106 SEPTEMBER 27, 2000

Change the CalcBean and JBonusBean Code

Because BonusBean provides its own SQL code, the CalcBean.calcbonus method, which

creates BonusBean instances, has to be changed to throw java.sql.SQLException. Here is

one way to do make that change:

public class CalcBean implements SessionBean {

BonusHome homebonus;

public Bonus calcBonus(int multiplier,

double bonus, String socsec)

throws RemoteException,

SQLException,

CreateException {

Bonus theBonus = null;

double calc = (multiplier*bonus);

try {

InitialContext ctx = new InitialContext();

Object objref = ctx.lookup("bonus");

homebonus = (BonusHome)

PortableRemoteObject.narrow(

objref, BonusHome.class);

} catch (Exception NamingException) {

NamingException.printStackTrace();

}

//Store data in entity Bean

theBonus=homebonus.create(calc, socsec);

return theBonus;

}

The JBonusBean class has to be changed to catch the SQLException thrown by CalcBean.

DuplicateKeyExcpetion is a sublcass of CreateException, so it will be caught by the

catch (javax.ejb.CreateException e) statement.

public double getBonusAmt() {

if(strMult != null){

Integer integerMult = new Integer(strMult);

int multiplier = integerMult.intValue();

try {

double bonus = 100.00;

theCalculation = homecalc.create();

Bonus theBonus = theCalculation.calcBonus(

multiplier, bonus, socsec);

Bonus record = theCalculation.getRecord(

socsec);

bonusAmt = record.getBonus();

socsec = record.getSocSec();

} catch (java.sql.SQLException e) {

this.bonusAmt = 0.0;

Tải ngay đi em, còn do dự, trời tối mất!