1:mysql数据库存储pdf流字段为:filed name: filestream type: MEDIUMBLOB
2:导入pdf文件到mysql 数据库
private
void
doWrite()
...
{

try ...{

if (new File("D:/Sun.pdf").exists()) ...{
FileInputStream fis = new FileInputStream(new File(
"D:/Sun.pdf"));
PreparedStatement pstmt = cnn
.prepareStatement("insert into tb(filestream) values(?) ");
pstmt.setBinaryStream(1, fis, 1024);
pstmt.execute();
}
} catch (Exception e) ...{
e.printStackTrace();
}
}
3:从mysql数据库读取pdf流到网页客户端显示
private
void
doRead(HttpServletRequest request, HttpServletResponse response)
...
{

try ...{
ByteArrayOutputStream ba = new ByteArrayOutputStream();
Statement stmt = cnn.createStatement();
ResultSet rs = stmt.executeQuery("select filestream from tb where id=1");
rs.next();
InputStream is = rs.getBinaryStream(1);
本文档介绍如何使用Java将PDF文件导入到MySQL数据库中,存储为MEDIUMBLOB类型,并从数据库中读取PDF流以在网页上显示。此外,还涉及到中文乱码问题的解决,通过引入iText相关的jar包来处理。完整源码可供参考。
最低0.47元/天 解锁文章

1135

被折叠的 条评论
为什么被折叠?



