欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jdbc调用存储过程。 JDBCSQL 

程序员文章站 2022-07-12 10:55:37
...
基本上没用过,快忘记了。
public static void setDeathAge(Poet dyingBard, int age);
    throws SQLException
{
   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();;
   }
}
//存储过程sql
[pre]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;[/pre]
相关标签: JDBC SQL