일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 다운캐스팅
- 이클립스
- 전자정부
- Login with OAuth Authentication
- Random
- 단축키
- IBatis procedure
- 형변환
- 로또
- jquery
- 자바
- 다형성
- angular2
- 야구게임
- 상속
- while
- full text indexing
- Validations
- 자바 야구게임
- 업캐스팅
- 전체
- Full text
- 25가지 효율적인 sql작성법
- 스프링
- 상속예제
- 추상클래스
- 가변인자
- 전체텍스트
- 페이징
Archives
- Today
- Total
nalaolla
우편번호 검색 본문
728x90
반응형
ZipCodeMain.java
- package test.com.zipcode;
- import java.sql.CallableStatement;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class ZipCodeMain {
- public static final String DRIVER_NAME = "oracle.jdbc.driver.OracleDriver";
- public static final String URL = "jdbc:oracle:thin:@localhost:1521:javagroup";
- public static final String USER_ID = "java_project";
- public static final String USER_PWD = "hi123456";
- public Connection getConn() {
- Connection con = null;
- try {
- Class.forName(DRIVER_NAME);
- con = DriverManager.getConnection(URL, USER_ID, USER_PWD);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return con;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ZipCodeMain zm = new ZipCodeMain();
- ZipCodeDAO dao = new ZipCodeDAOImpl();
- ZipcodeVO vo = new ZipcodeVO();
- String addr_String = "영등동";
- int addr_cnt = 0;
- Connection con = zm.getConn();
- ResultSet rs = null;
- ResultSet rs1 = null;
- CallableStatement statement = null;
- try {
- String sql = "call UP_ZIPCODE_SEARCH(?, ?, ?)";
- statement = con.prepareCall(sql);
- statement.setString(1, addr_String);
- statement.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
- statement.registerOutParameter(3, oracle.jdbc.OracleTypes.NUMBER);
- statement.execute();
- rs = (ResultSet) statement.getObject(2);
- while(rs.next()) {
- System.out.print(rs.getInt("zipcode") + " ");
- System.out.print(rs.getString("sido") + " ");
- System.out.print(rs.getString("sigungu") + " ");
- System.out.println(rs.getString("b_dong_name"));
- }
- System.out.println("결과물수 : " + statement.getInt(3));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
ZipCodeDAO.java
- package test.com.zipcode;
- import java.util.List;
- public interface ZipCodeDAO {
- public List<ZipcodeVO> search();
- }
ZipCodeDAOImpl.java
- package test.com.zipcode;
- import java.util.List;
- public class ZipCodeDAOImpl implements ZipCodeDAO {
- @Override
- public List<ZipcodeVO> search() {
- // TODO Auto-generated method stub
- return null;
- }
- }
ZipcodeVO.java
- package test.com.zipcode;
- public class ZipcodeVO {
- String search;
- String addr;
- int zipcode;
- public String getSearch() {
- return search;
- }
- public void setSearch(String search) {
- this.search = search;
- }
- public String getAddr() {
- return addr;
- }
- public void setAddr(String addr) {
- this.addr = addr;
- }
- public int getZipcode() {
- return zipcode;
- }
- public void setZipcode(int zipcode) {
- this.zipcode = zipcode;
- }
- }
DB설정
패키지 생성
- CREATE OR REPLACE PACKAGE ZIPCODE_PKG AS
- /* TODO enter package declarations (types, exceptions, methods etc) here */
- type RSLIST IS ref cursor;
- END ZIPCODE_PKG;
프로시저 생성
- CREATE OR REPLACE PROCEDURE UP_ZIPCODE_SEARCH
- (
- ADDR IN VARCHAR2,
- LIST OUT ZIPCODE_PKG.RSLIST,
- CNT OUT NUMBER
- ) AS
- BEGIN
- --전체 검색 데이터 count
- SELECT count(zseq) INTO CNT FROM zipcode WHERE B_dong_name LIKE '%'|| ADDR ||'%';
- --검색 ResultSet 커서에 담기
- OPEN LIST FOR
- SELECT zipcode, sido, sigungu, b_dong_name FROM ZIPCODE WHERE B_DONG_NAME LIKE '%'|| ADDR ||'%';
- END UP_ZIPCODE_SEARCH;
728x90
반응형
'JAVA > 99. ETC' 카테고리의 다른 글
스프링부트 에서 카프카 써서 메시지 주고 받아보기 (0) | 2020.11.26 |
---|---|
이클립스 네이버 SVN설정 (0) | 2016.03.15 |
이클립스 SVN 설정 (0) | 2016.03.15 |
이클립스 class 디컴파일 설정하기 (0) | 2015.12.16 |
Creating a JDBC GUI Application (0) | 2015.12.08 |