Abdullah047

WriteClob_SQL

Sep 2nd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 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.sql.Connection;
  13. import java.sql.DriverManager;
  14. import java.sql.SQLException;
  15. import java.sql.PreparedStatement;
  16. /**
  17.  *
  18.  * @author Abdullah
  19.  */
  20. public class WriteBLOB {
  21.     public static void main(String[] args) throws SQLException, FileNotFoundException{
  22.         String url="jdbc:mysql://localhost:3306/demo?autoReconnect&useSSL=false";
  23.         String user="root";
  24.         String password="abdullah";
  25.         String SQL=
  26.                 "UPDATE employee1 SET resume=?  WHERE id=2"
  27.                 ;
  28.         File file=new File("D:\\jdbc-blob\\sample_resume.pdf");
  29.         FileInputStream IS=new FileInputStream(file);
  30.        
  31.     Connection connect=DriverManager.getConnection(url,user,password);
  32.     PreparedStatement PS=connect.prepareStatement(SQL);
  33.         PS.setBinaryStream(1, IS);
  34.     PS.executeUpdate();
  35.    
  36.    
  37.    
  38.     }
  39. }
Add Comment
Please, Sign In to add comment