Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package sqltest;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.*;
- /**
- *
- * @author Abdullah
- */
- public class ReadBLOB {
- public static void main(String[] args) throws SQLException, FileNotFoundException, IOException{
- String URL="jdbc:mysql://localhost:3306/demo?autoReconnect";
- String user="root";
- String Password="abdullah";
- String SQL=
- "SELECT resume FROM employee1 WHERE id=2"
- ;
- File file;
- InputStream IS;
- FileOutputStream OS;
- Connection connect=DriverManager.getConnection(URL,user,Password);
- Statement NS=connect.createStatement();
- ResultSet result= NS.executeQuery(SQL);
- file=new File("C://Users//Abdullah//Desktop//SQLTEST.pdf");
- OS=new FileOutputStream(file);
- if(result.next()){
- IS=result.getBinaryStream("resume");
- byte[] buffer=new byte[1024];
- while(IS.read(buffer)>0){
- OS.write(buffer);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment