Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File pdfFile = new File("...test.pdf");
- byte[] pdfData = new byte[(int) pdfFile.length()];
- DataInputStream dis = new DataInputStream(new FileInputStream(pdfFile));
- dis.readFully(pdfData); // read from file into byte[] array
- dis.close();
- String myConnectionString = "jdbc:mysql:...";
- String user = "user";
- String password = "password";
- dbConnection = DriverManager.getConnection(myConnectionString, user, password);
- PreparedStatement ps = dbConnection.prepareStatement(
- "INSERT INTO project (filename, pdf_file) VALUES (?,?)");
- ps.setString(1, "test");
- ps.setBytes(2, pdfData); // byte[] array
- ps.executeUpdate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement