Simple Oracle Procedure:
create procedure set_death_age(poet VARCHAR2, poet_age NUMBER)
poet_id NUMBER;
begin
SELECT id INTO poet_id FROM poets WHERE name = poet;
INSERT INTO deaths (mort_id, age) VALUES (poet_id, poet_age);
end set_death_age;
Calling simple procedure from Java
Connection con = null;
CallableStatement proc = null;
try
{
con = connectionPool.getConnection();
proc = con.prepareCall("{ call set_death_age(?, ?) }");
proc.setString(1, dyingBard.getName());
proc.setInt(2, age);
proc.execute();
}
finally
{
try
{
proc.close();
}
catch (SQLException e) {}
con.close();
}
No comments:
Post a Comment