Guest User

Untitled

a guest
May 21st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. try {
  2. Class.forName("com.mysql.jdbc.Driver");
  3. Connection con = DriverManager.getConnection("jdbc:mysql://localhost/EMP", "root", "");
  4. PreparedStatement ps = con.prepareStatement("insert into imgtable values(?,?)");
  5. ps.setString(234, "tester");
  6. FileInputStream fin = new FileInputStream("d:\resume.pdf");
  7. ps.setBinaryStream(2, fin, fin.available());
  8. int i = ps.executeUpdate();
  9. System.out.println(i + " Your details successfully uploaded");
  10. con.close();
  11. } catch (Exception e) {
  12. e.printStackTrace();
  13. }
  14.  
  15. stmt = con.prepareStatement("SELECT myimg from imgtable where mykey = ?");
  16.  
  17. stmt.setString(1, "tester");
  18. rs = stmt.executeQuery();
  19. if (!rs.next()) {
  20. System.out.println("File not found in the database.");
  21. } else {
  22. Blob b = rs.getBlob(1);
  23. BufferedOutputStream os;
  24. File f = new File("d:\retrievedResume.pdf");
  25.  
  26.  
  27. os = new BufferedOutputStream(new FileOutputStream(f));
  28. os.write(b.getBytes(0, (int) b.length()), 0, (int) b
  29. .length());
  30. os.flush();
  31. os.close();
  32. }
Add Comment
Please, Sign In to add comment