我正在尝试将我创建的数据库表中的所有字段写入PDF。这是我的代码:
Document snapshot = new Document();
ArrayList<History> historyList = new ArrayList<History>();
Connection con = dbConnection();
String query = "SELECT * FROM apm_system.history";
Statement st;
ResultSet rs;
try {
st = con.createStatement();
rs = st.executeQuery(query);
History history;
while (rs.next()) {
history = new History(rs.getString("TransactionID"),
rs.getString("On"), rs.getString("By"), rs.getString("Date"),
rs.getString("Time"));
historyList.add(history);
}
PdfWriter.getInstance(snapshot, new FileOutputStream("snapshot.pdf"));
snapshot.open();
for (int i = 0; i < historyList.size(); i++) {
String temp = historyList.get(i).toString();
Paragraph p = new Paragraph(temp + "\n");
snapshot.add(p);
}
} } catch (Exception e) {
System.out.println(e);
}
snapshot.close();
我的PDF文件如下所示:
apm.History@6dec77
apm.History@2669323d
apm.History@33eea10d
apm.History@5e850105
我的代码不是从数据库中写入实际字段,而只是引用它们。我不确定我是否使用了正确的术语,而不是输出:ID32321 User Admin 2017/10/12 14:24。它输出:apm.History@6dec77到PDF。 我该如何解决?提前谢谢。
答案 0 :(得分:2)
在toString
类中添加History
方法,输出除对象引用之外的其他内容。