ストアド

ストアドの定義

create or replace procedure update_syohin (
  pi_syohin_id   in number,
  pi_syohin_name in varchar2,
  pi_remarks     in varchar2,
  po_syohin_count out number
)
is 
begin
  select count(syohin_id) into po_syohin_count
    from nms_t_syohin_1
   where syohin_id = pi_syohin_id;
   if (po_syohin_count > 0) then
       update nms_t_syohin_1 
           set syohin_name = pi_syohin_name,
                 remarks = pi_remarks
        where syohin_id = pi_syohin_id;
        po_syohin_count := SQL%ROWCOUNT;
   else
       po_syohin_count := -1;
   end if;
end;

じゃば

import java.sql.*;
import static java.lang.System.out;
public class Hoge {
    public static void main(String[] args) throws Exception {
        Class.forName("oracle.jdbc.OracleDriver");
        
        Connection conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@192.168.xxx.xx:1521:xxxx",
                "xxx1",
                "xxx1");
        CallableStatement cs = null;
        try {
            cs = conn.prepareCall("{call update_syohin(?,?,?,?)}");
            cs.setInt(1, new Integer(1));
            cs.setString(2, "hoge");
            cs.setString(3, "moge");
            cs.registerOutParameter(4, Types.NUMERIC);

            int i = cs.executeUpdate();

            out.println(cs.getInt(4));

        } finally {
            if (cs != null) cs.close();
            if (!conn.isClosed()) conn.close();
        }
    }
}