Hello guys I need help. I have code below which saves the pdf file into mysql database it works perfectly, but i don't know how to retrieve the pdf file into my pc. Any idea how to do it? Thanks
try{
//connection string
File pdfFile = new File ("d:\\modularing.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();
PreparedStatement ps=con.prepareStatement("INSERT INTO filetable (" + "ID, " +
"PDF_file " + ") VALUES (?,?)");
ps.setString(1, "newpdffile");
ps.setBytes(2, pdfData); // byte[] array
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
请参阅Blob的API,尤其是getBinaryStream()方法,该方法可检索InputStream
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.