프로시저 생성
ALTER PROCEDURE [dbo].[SP_LEGACY_INS] |
프로시저 실행
DECLARE |
자바에서 프로시저 실행
import java.io.File; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Types; import java.util.Properties; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ProcedureTest { private final static Logger log = LoggerFactory.getLogger(ProcedureTest.class); private Connection conn; private void conn() throws Exception { String filePath = getClass().getResource("db.properties").getPath(); File file = new File(filePath); if(file.exists()) { Properties prop = new Properties(); prop.load(LegacyBatchBackup.class.getResourceAsStream("db.properties")); Class.forName(prop.getProperty("ewppis.mssql.driver")); String url = prop.getProperty("ewppis.mssql.url") + ";user=" + prop.getProperty("ewppis.mssql.user") + ";password=" + prop.getProperty("ewppis.mssql.password") + ";"; conn = DriverManager.getConnection(url); } else { log.error("DB 접속정보가 없습니다."); } } @Test public void test1() throws Exception { CallableStatement cstmt = null; try { conn(); String sql = "{CALL SP_LEGACY_INS(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"; cstmt = conn.prepareCall(sql); cstmt.setString(1, "PIS"); cstmt.setString(2, "C"); cstmt.setString(3, "admin"); cstmt.setString(4, "이순신"); cstmt.setString(5, "PID10"); cstmt.setString(6, "VPN - 신청"); cstmt.setString(7, "1"); cstmt.setString(8, "127.0.0.1"); cstmt.setString(9, "123456-1234567"); cstmt.registerOutParameter(10, Types.INTEGER); cstmt.registerOutParameter(11, Types.VARCHAR); cstmt.executeUpdate(); log.debug("return : {}", cstmt.getString(10)); log.debug("return : {}", cstmt.getString(11)); } catch (Exception e) { } finally { if(cstmt != null) cstmt.close(); if(conn != null) conn.close(); } } } |