存储过程是数据库管理系统的专用术语,相当与普通编程语言的函数、过程。普通过程的作用是完成特定的工作,存储过程专用于处理数据库的数据更新、查询。普通工程往往有编译程序生成,存在与操作系统的特定文件中,存储过程由数据库管理系统生成存放到数据库的数据字典中。直接通过SQL语句访问数据库时,SQL语句以字符串的形式提交给服务器,服务器要经过分析、编译,然后才执行;若将SQL语句写到存储过程中,那么分析和编译是在生成存储过程时完成的,需要执行时只需要调用存储过程就可以了。如下SQL语句完成数据的更新,可以将他们写到存储过程中
update table1 set column1='1',column2='2';
update table2 set column1='11',column2='22';
若将他们直接提交给服务器每一条语句都需要经过分析、编译、执行。
将他们写入如下存储过程中(对oracle)create or replace procedure proc_name is
begin
 update table1 set column1='1',column2='2';
 update table2 set column1='11',column2='22';
end proc_name;需要执行更新时直接调用(exec proc_name)存储过程proc_name。若你一次要执行很多SQL语句而且这些语句要反复执行就应该写成存储过程。

解决方案 »

  1.   

    public double text(Connection connection,String employeeId)Throws SQLException{
      CallableStatement cstmt=connection.prepareCall("{call getEmployeeStartSalary (?,?)}");
      cstmt.setString(1,employeeId);
      cstmt.registerOutParameter(2,java.sql.Types.DOUBLE);
      cstmt.executeQuery();
      double salary=cstmt.getDouble(2);
      return salary;
    }help me to explain the function ,thank you!
      

  2.   

    简单的说:就是预编译的一组sql语句,用于执行一批数据库操作.
    由于其保存在数据库缓冲区中,所以无需编译可直接调用.执行的效率很高!
      

  3.   

    public double text(Connection connection,String employeeId)Throws SQLException{
      CallableStatement cstmt=connection.prepareCall("{call getEmployeeStartSalary (?,?)}");
      cstmt.setString(1,employeeId);
      cstmt.registerOutParameter(2,java.sql.Types.DOUBLE);
      cstmt.executeQuery();
      double salary=cstmt.getDouble(2);
      return salary;
    }help me to explain the function ,thank you!