Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. File pdfFile = new File("...test.pdf");
  2. byte[] pdfData = new byte[(int) pdfFile.length()];
  3. DataInputStream dis = new DataInputStream(new FileInputStream(pdfFile));
  4. dis.readFully(pdfData); // read from file into byte[] array
  5. dis.close();
  6.  
  7. String myConnectionString = "jdbc:mysql:...";
  8. String user = "user";
  9. String password = "password";
  10. dbConnection = DriverManager.getConnection(myConnectionString, user, password);
  11. PreparedStatement ps = dbConnection.prepareStatement(
  12. "INSERT INTO project (filename, pdf_file) VALUES (?,?)");
  13. ps.setString(1, "test");
  14. ps.setBytes(2, pdfData); // byte[] array
  15. ps.executeUpdate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement