0
您好,我需要帮助。我有下面的代码将pdf文件保存到mysql数据库中,它完美的工作,但我不知道如何检索到我的电脑的PDF文件。任何想法如何做到这一点?由于如何使用java从MySql数据库中检索Blob pdf文件
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();
}
您应该使用[InputStream的(https://docs.oracle.com/javase/7 /docs/api/java/io/InputStream.html)是读取blob的关键,请尝试搜索API以读取blob pdf文件。 –