-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package day05; | ||
import java.sql.*; | ||
import common.DBUtil; | ||
/* | ||
CREATE OR REPLACE PROCEDURE MEMO_ALL( | ||
MYCR OUT SYS_REFCURSOR) | ||
IS | ||
BEGIN | ||
OPEN MYCR FOR | ||
SELECT IDX, NAME, MSG, WDATE FROM MEMO | ||
ORDER BY IDX DESC; | ||
END; | ||
/ | ||
* */ | ||
public class CallableStatementTest3 { | ||
|
||
public static void main(String[] args) | ||
throws SQLException | ||
{ | ||
Connection con=DBUtil.getCon(); | ||
String sql="{call memo_all(?)}"; //SYS_REFCURSOR | ||
|
||
CallableStatement cs=con.prepareCall(sql); | ||
cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR); | ||
|
||
//ResultSet rs=cs.executeQuery(); [x] 에러 발생함 | ||
cs.execute(); | ||
|
||
ResultSet rs=(ResultSet)cs.getObject(1); | ||
|
||
while(rs.next()) { | ||
int idx=rs.getInt("idx"); | ||
String name=rs.getString("name"); | ||
String msg=rs.getString("msg"); | ||
Date wdate=rs.getDate("wdate"); | ||
System.out.println(idx+"\t"+name+"\t"+msg+"\t"+wdate); | ||
}//while-------- | ||
rs.close(); | ||
cs.close(); | ||
con.close(); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package day05; | ||
import java.sql.*; | ||
|
||
import javax.swing.JOptionPane; | ||
|
||
import common.DBUtil; | ||
/* | ||
create or replace procedure emp_forjava( | ||
pdno in emp.deptno%type, | ||
mycr out sys_refcursor) | ||
is | ||
begin | ||
OPEN mycr for | ||
select ename,job,hiredate,dname,loc from | ||
(select * from emp where emp.deptno=pdno) A join dept D | ||
on A.deptno = D.deptno; | ||
end; | ||
/ | ||
* */ | ||
|
||
public class CallableStatementTest4 { | ||
|
||
public static void main(String[] args) throws Exception { | ||
String dno=JOptionPane.showInputDialog("검색할 부서번호 입력하세요: "); | ||
if(dno==null) return; | ||
|
||
// 부서번호를 인파라미터로 전달하면 해당 부서에 있는 사원정보(사원명, 업무, 입사일)와 부서정보(부서명,근무지)를 | ||
//가져오는 프로시저를 작성하고 이것을 자바에서 호출해서 결과 데이터를 출력하세요 | ||
Connection con=DBUtil.getCon(); | ||
String sql="{call emp_forjava(?,?)}"; | ||
CallableStatement cs=con.prepareCall(sql); | ||
cs.setString(1, dno); | ||
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR); | ||
cs.execute(); | ||
|
||
ResultSet rs=(ResultSet)cs.getObject(2); | ||
System.out.println(dno+"번 부서 사원 목록-------------------------------"); | ||
while(rs.next()) { | ||
String ename=rs.getString(1); | ||
String job=rs.getString(2); | ||
Date hiredate=rs.getDate(3); | ||
String dname=rs.getString(4); | ||
String loc=rs.getString(5); | ||
System.out.println(ename+"\t"+job+"\t"+hiredate+"\t"+dname+"\t"+loc); | ||
}//while------ | ||
rs.close(); | ||
cs.close(); | ||
con.close(); | ||
|
||
} | ||
|
||
} |