Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package com.file;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8.  
  9. import oracle.sql.BLOB;
  10.  
  11. public class FileDownload {
  12.  
  13. public static void main(String[] args) {
  14. // TODO Auto-generated method stub
  15. try
  16. {
  17. Class.forName("oracle.jdbc.driver.OracleDriver");
  18. Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","kannan","test123");
  19. Statement st=con.createStatement();
  20. ResultSet rs=st.executeQuery("select * from kannan1");
  21. rs.next();
  22. System.out.println(rs.getString(1));
  23. BLOB blop=(BLOB) rs.getBlob(2);
  24. byte data[]=blop.getBytes(1,(int) blop.length());
  25. FileOutputStream fout=new FileOutputStream("d:\\kannan1.pdf");
  26. fout.write(data);
  27. System.out.println("File Download Successfully");
  28. }catch(Exception e)
  29. {
  30. System.out.println(e);
  31. }
  32.  
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement