Abdullah047

ReadBlob

Sep 2nd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package sqltest;
  7.  
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.FileNotFoundException;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import java.io.InputStream;
  14. import java.sql.DriverManager;
  15. import java.sql.SQLException;
  16. import java.sql.*;
  17. /**
  18.  *
  19.  * @author Abdullah
  20.  */
  21. public class ReadBLOB {
  22.     public static void main(String[] args) throws SQLException, FileNotFoundException, IOException{
  23.         String URL="jdbc:mysql://localhost:3306/demo?autoReconnect";
  24.         String user="root";
  25.         String Password="abdullah";
  26.         String SQL=
  27.    "SELECT resume FROM employee1 WHERE id=2"
  28.                 ;
  29.         File file;
  30.         InputStream IS;
  31.         FileOutputStream OS;
  32.        
  33.         Connection connect=DriverManager.getConnection(URL,user,Password);
  34.         Statement NS=connect.createStatement();
  35.        ResultSet result= NS.executeQuery(SQL);
  36.       file=new File("C://Users//Abdullah//Desktop//SQLTEST.pdf");
  37.       OS=new FileOutputStream(file);
  38.       if(result.next()){
  39.          
  40.       IS=result.getBinaryStream("resume");
  41.      
  42.      byte[]  buffer=new byte[1024];
  43.       while(IS.read(buffer)>0){
  44.            OS.write(buffer);
  45.      
  46.               }
  47.       }      
  48.        
  49.        
  50.         }
  51. }
Add Comment
Please, Sign In to add comment