📄 16f.txt
字号:
public AccountPK ejbCreate(String name, float balance) throws RemoteException, CreateException
{
try
{
// 查找主键,看看这个Bean有没有被实例化
ejbFindByPrimaryKey(new AccountPK(name));
// 如果被实例化,就抛出一个异常
throw new DuplicateKeyException();
}
catch(ObjectNotFoundException e)
{
// 没有,就继续
}
_name = name;
_balance = balance;
Connection connection = null;
PreparedStatement statement = null;
try
{
//和数据库建立连接
connection = getConnection();
//设置SQL语句
statement = connection.prepareStatement("INSERT INTO Savings_Accounts (name, balance) VALUES (?, ?)");
//设置参数
statement.setString(1, _name);
statement.setFloat(2, _balance);
//执行SQL
if(statement.executeUpdate() != 1)
{
throw new CreateException("Could not create: " + name);
}
return new AccountPK(name);
}
catch(SQLException e)
{
throw new RemoteException("Could not create: " + name, e);
}
finally
{
try
{
if (statement != null)
{
statement.close();
}
if (connection != null)
{
connection.close();
}
}
catch (SQLException sqe)
{
throw new RemoteException("Could not create, close statement, connection: " + name, sqe);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -