Springframework에서 MS-SQL에 BLOB로 저장되어 있는 이미지를 불러와 파일로 저장

String sql = "select picture from users where id=?";
Object[] args = { userId };
Blob rsPhoto = (Blob)getJdbcTemplate().queryForObject(sql, args, Blob.class);


try {
            for(int i = 0; i < rsPhoto.length(); i++)
                {
                    String upDir = "c:\\imgs\\";
                    Random Number = new Random();
                    int Dice_number;
                    String strPath;
                   
                    Dice_number = Number.nextInt(999999);
                    strPath = upDir + Dice_number+".jpg";
                   
                    try {
                        logger.debug(rsPhoto == null ? "null " : "not null");
                        FileOutputStream newFile = new FileOutputStream(strPath);
                        newFile.write(rsPhoto.getBytes(1, (int)rsPhoto.length()));                       
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
        } catch (SQLException e) {
            e.printStackTrace();
        }

728x90
BLOG main image
"그게 뭐 어쨌다는 거냐?" 늘 누가 나에게 나에대한 말을할 때면 이말을 기억해라. by nobang

카테고리

nobang이야기 (1933)
Life With Gopro (7)
Life With Mini (79)
Diary (971)
너 그거 아니(do you know) (162)
난 그래 (159)
Study (290)
속지말자 (10)
Project (34)
Poem (15)
Song (0)
Photo (113)
낙서장 (45)
일정 (0)
C.A.P.i (2)
PodCast (0)
nobang (27)
고한친구들 (4)
recieve (0)
History (0)
android_app (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :