【发布时间】:2015-05-25 09:12:28
【问题描述】:
我正在用jsp编码。我已经使用 itext 生成了 pdf。并尝试将文档保存到数据库(mysql)中。
String filename="patient.pdf";
response.setContentType("application/pdf");
Document document = new Document();
PdfWriter pd= PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
document.addTitle("Dentistree");
document.add(new Paragraph("Hello,"+"\n\t"+"Thanks for making an appointment to Dentistree"+"\n\t"+"You have provided case history for your appointment. Here are the details of the appointment\n\t"+"List of the diseases that you are suffering through are as follows:"+di+"\n\n\nAre you pregnant?\t"+pregnant+"\n\n\nAre nursing a child?\t"+nursing+"\n\n\nDo you chew pan-masala?\t"+pan+"\n\n\nDo you smoke?\t"+smoke+"\n\n\nAllergic?\t"+all+"List of the medicines:"+medicines));
document.close();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dentistree","root", "tiger");
String str="insert into appointment(email,pdf) values(?,?)";
PreparedStatement st = con.prepareStatement(str);
st.setString(1, mail);
st.setBlob(2,pd);
Java 编码新手。请帮忙
【问题讨论】:
-
任何问题/错误/异常?请问您有什么问题?
-
如果您需要将 PDF 作为 BLOB 存储到数据库中,为什么要在文件系统上创建文件?在内存中创建 PDF 作为
ByteArrayOutputStream并将生成的byte[]存储在您的数据库中。 -
你真的执行了语句吗?