作成したデータベースのテーブルからすべてのフィールドを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/1214:24。apm.History@6dec77をPDFに出力します。これを修正するにはどうすればよいですか?前もって感謝します。
クラスにtoString
メソッドを追加してHistory
、オブジェクト参照以外のものを出力します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加