일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- String[]
- eclipse hotdeploy
- extundelete
- 접속ip
- KOSA
- update
- 2개 테이블
- 첫주 및 마지막주 날짜 전체 포함
- jquery selectbox change
- mysql
- Oracle
- map api v3
- 아이폰키보드
- multipart
- partition by
- ajax async
- 컴퓨터 드라이버
- http https
- TM128
- ajax 동기방식처리
- ant path pattern
- 폐업자에 대한 업종등의 정보내역
- group by max
- 주소 좌표변환
- 한국소프트웨어산업협회
- remote ip
- 서브쿼리
- mysql trigger
- String 배열
- checkbox 값처리
- Today
- Total
하은양 믿음군 효실맘 호홍홍집s
oracle BLOB로 저장된 file을 서버에 저장하기 본문
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import = "oracle.jdbc.driver.OracleResultSet"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.sql.DriverManager" %>
<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.Statement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "java.sql.Timestamp" %>
<%@ page import = "java.io.*" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.net.URLConnection"%>
<%@ page import = "java.net.HttpURLConnection"%>
<%@ page import = "java.net.URL"%>
<%@ page import = "java.net.URLEncoder"%>
<%@ page import = "org.springframework.context.ApplicationContext"%>
<%@ page import = "org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@ page import = "javax.sql.DataSource"%>
<%
// 원본 DB
String SrcDriver = "jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:ORCL"; // 소스 DB driver
String SrcUser = ""; // DB USer
String SrcPass = ""; // DB Password
Connection SrcConn = null;
Statement SrcStmt = null;
/* 고정값 RFC DB */
ApplicationContext context = new ClassPathXmlApplicationContext("datasource.xml");
DataSource ds = (DataSource)context.getBean("IamDataSource");
Connection DesConn = null;
Statement DesStmt = null;
PreparedStatement destPsmt = null;
ResultSet rs = null;
ResultSet rs2 = null;
ResultSet rs3 = null;
ResultSet rs4 = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
String sSql = "";
InputStream is = null;
FileOutputStream fos = null;
try {
try {
SrcConn = DriverManager.getConnection(SrcDriver, SrcUser, SrcPass);
if(SrcConn != null) SrcStmt = SrcConn.createStatement();
} catch(SQLException sqlSubEx) {
out.print("sql sub error::"+sqlSubEx);
}finally{
out.println("SrcConn-start::"+SrcConn+"<br/>");
out.println("SrcStmt-start::"+SrcStmt+"<br/>");
}
String sTableName = "";
String saveFilePath = "/home/www/upload_data/board_data/";
// Get File NameList
sSql = "SELECT HPAGE.NAME, HPAGE.FILE_NAME,HPAGE.BLOB_CONTENT,HPAGE.DOC_SIZE " +
" FROM CM8200T LAW, HPAGE_UPLOAD_FILE HPAGE " +
" WHERE LAW.FULL_FILE_NAME = HPAGE.NAME " +
" ORDER BY LAW.LAW_ID, LAW.YMD, LAW.FILE_SNO ";
rs = SrcStmt.executeQuery(sSql);
int countFileID = 0;
while(rs.next()){
String sFileID = rs.getString("NAME"); if(sFileID == null) sFileID = "";
String sFileName = rs.getString("FILE_NAME"); if(sFileName == null) sFileName = "";
oracle.sql.BLOB blob = ((OracleResultSet)rs).getBLOB("BLOB_CONTENT");
is = (blob.getBinaryStream());
fos = new FileOutputStream(saveFilePath+countFileID+sFileName); // 복사위치
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while((length=is.read(buffer))!=-1){
fos.write(buffer,0,length);
}
fos.close();
is.close();
countFileID++;
}
if(rs != null) try { rs.close(); } catch(SQLException sqlSubEx) {}
} catch(SQLException sqlEx) {
out.print("sql error::"+sqlEx);
}catch(Exception ex){
out.println("sSql::" + sSql + "<br />");
out.println("error::" + ex);
}finally{
if (fos != null) try { fos.close(); } catch(Exception ex) {}
if (is != null) try { is.close(); } catch(Exception ex) {}
if (rs != null) try { rs.close(); } catch(SQLException ex) {}
if (rs2 != null) try { rs2.close(); } catch(SQLException ex) {}
if (rs3 != null) try { rs3.close(); } catch(SQLException ex) {}
if (rs4 != null) try { rs4.close(); } catch(SQLException ex) {}
if (SrcStmt != null) try { SrcStmt.close(); } catch(SQLException ex) {}
if (DesStmt != null) try { DesStmt.close(); } catch(SQLException ex) {}
if (destPsmt != null) try { destPsmt.close(); } catch(SQLException ex) {}
if (SrcConn != null) try { SrcConn.close(); } catch(SQLException ex) {}
if (DesConn != null) try { DesConn.close(); } catch(SQLException ex) {}
}
%>
'가벼운 배움 > jsp' 카테고리의 다른 글
모바일기기 접속 여부 체크하기. (0) | 2016.06.28 |
---|---|
javascript encodeURIComponent() 함수를 jsp URLDecode.decode()변환시 한글깨짐 (1) | 2016.06.14 |
유니코드로된 한글을 한글로 변환하기... (0) | 2016.06.03 |
한글인코딩확인방법2 (0) | 2016.06.03 |
jsp http를 https로 전환 (0) | 2016.05.02 |