30.01.2015 Views

des enterprise beans - Département Informatique

des enterprise beans - Département Informatique

des enterprise beans - Département Informatique

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Exemple du bean entité bank<br />

}<br />

}<br />

throw new RemoteException("Impossible de trouver : " + key, e);<br />

public java.util.Enumeration ejbFindAccountsLargerThan(float balance)<br />

throws RemoteException, FinderException {<br />

try {<br />

Connection connection = getConnection();<br />

PreparedStatement statement = connection.prepareStatement<br />

("SELECT name FROM Savings_Account WHERE balance > ");<br />

statement.setFloat(1, balance);<br />

ResultSet resultSet = statement.executeQuery();<br />

Vector keys = new Vector();<br />

while(resultSet.next()) {<br />

String name = resultSet.getString(1);<br />

keys.addElement(new AccountPK(name));<br />

}<br />

statement.close();<br />

connection.close();<br />

return keys.elements();<br />

} catch(SQLException 3) {<br />

throw new RemoteException("Impossible findAccountsLargerThan : " +<br />

balance, e);<br />

}<br />

}<br />

public void ejbLoad() throws RemoteException {<br />

// obtient le nom de la clé primaire<br />

_name = (AccountPK) _context.getPrimaryKey()).name;<br />

try {<br />

Connection connection = getConnection();<br />

PreparedStatement statement = connection.prepareStatement<br />

("SELECT balance FROM Savings_Account WHERE name = ");<br />

statement.setString(1, _name);<br />

ResultSet resultSet = statement.executeQuery();<br />

if(!resultSet.next()) {<br />

throw new RemoteException("Compte introuvable : " + _name);<br />

}<br />

_balance = resultSet.getFloat(1);<br />

statement.close();<br />

connection.close();<br />

} catch(SQLException e) {<br />

throw new RemoteException("Impossible de charger : " + _name, e):<br />

}<br />

}<br />

public void ejbStore() throw RemoteException {<br />

try {<br />

Connection connection = getConnection();<br />

PreparedStatement statement = connection.prepareStatement<br />

("UPDATE Savings_Accounts SET balance = WHERE name = ");<br />

statement.setFloat(1, _balance);<br />

statement.setString(2, _name);<br />

statement.executeUpdate();<br />

10-18 Guide du dé veloppeur Enterprise JavaBeans

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!