일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- angular2
- full text indexing
- 상속
- 페이징
- while
- 업캐스팅
- 로또
- Full text
- Login with OAuth Authentication
- Validations
- IBatis procedure
- 단축키
- 자바 야구게임
- 자바
- 가변인자
- 전자정부
- 추상클래스
- 다운캐스팅
- 이클립스
- 형변환
- 전체텍스트
- 전체
- 스프링
- jquery
- Random
- 상속예제
- 야구게임
- 25가지 효율적인 sql작성법
- 다형성
Archives
- Today
- Total
nalaolla
프로시져 호출하여 리스트 출력 본문
728x90
반응형
- package test.com.board.view;
- import java.sql.CallableStatement;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- public class BoardMain {
- private static final String DRIVER_NAME = "oracle.jdbc.OracleDriver";
- private static final String URL = "jdbc:oracle:thin:@localhost:1521:XE";
- private static final String USER = "java_project";
- private static final String PASSWORD = "hi123456";
- public static void main(String[] args) {
- Connection conn = null;
- CallableStatement st = null;
- ResultSet rs = null;
- BoardMain bm = new BoardMain();
- try {
- conn = bm.getcon();
- String sql = "call Up_Get_Board_Tab(?)";
- st = conn.prepareCall(sql);
- st.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
- st.execute();
- rs = (ResultSet) st.getObject(1);
- ResultSetMetaData rmd = rs.getMetaData();
- System.out.print(rmd.getColumnName(1) + " ");
- System.out.print(rmd.getColumnName(2) + " ");
- System.out.print(rmd.getColumnName(3) + " ");
- System.out.print(rmd.getColumnName(4) + " ");
- System.out.print(rmd.getColumnName(5) + " ");
- while (rs.next()) {
- System.out.print(rs.getInt("num") + " ");
- System.out.print(rs.getString("title") + " ");
- System.out.print(rs.getString("content") + " ");
- System.out.print(rs.getString("writer") + " ");
- System.out.print(rs.getDate("regdate") + " ");
- }
- } catch (Exception e) {
- // TODO: handle exception
- } finally {
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- st.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public Connection getcon() {
- Connection conn = null;
- try {
- Class.forName(DRIVER_NAME);
- conn = DriverManager.getConnection(URL, USER, PASSWORD);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return conn;
- }
- }
728x90
반응형
'JAVA > 26. JDBC' 카테고리의 다른 글
java 코드 오라클 저장 프로시저 호출 (0) | 2015.12.09 |
---|---|
JDBC_간단게시판 (2) | 2015.12.09 |