저는 java에서 새로 생겼으며 itextpdf를 출력으로 사용합니다.
지금 당장이 문제로 인해 혼란 스럽습니다.
결과 집합을 데이터베이스에서 itextpdf로
내 문제는 데이터베이스에서 결과 집합을 PDF 형식으로 표시하고 싶다는 것입니다.
예를 들어,
이름
존
제인
메리
소니
킬
전, 3 열이
을 테이블을 설정하고이 데이터베이스에서 결과 집합입니다
이제 itextpdf의 출력은 다음과 같이 표시되어야합니다. 0 | 1234 |
| _____ 존 ______ | _____ 제인 _____ | _____ 메리 ____ |
| _____ 소니 _____ | _____ 키엘 _____ | _____________ |
결과가 모든 열에 삽입되기를 원하며이를 수행하는 방법을 모릅니다.
누구? 누군가가 나를 인도 할 수 있으면 좋을 것입니다.
Document document = new Document(PageSize.A4, 25, 25, 25, 25);
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("D:\\PURCHASEORDER\\"+see+".pdf"));
document.open();
try {
Class.forName(driver);
conn = DriverManager.getConnection(url+db, user, pass);
Statement st = conn.createStatement();
String zero = dates.getSelectedItem().toString();
String sql = "select name as hehe from names where servedate = '"+zero+"'";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
Rectangle react = writer.getPageSize();
PdfPTable table2 = new PdfPTable(new float[] { 3,3,3});
table2.setTotalWidth(527);
table2.getDefaultCell().setBorder(Rectangle.NO_BORDER);
PdfPCell cell = new PdfPCell(new Paragraph(""));
cell.setColspan(8);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBackgroundColor(BaseColor.GRAY);
table2.addCell(cell);
table2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
while(rs.next()){
String v1 = rs.getString("hehe");
FontFactory.getFont(FontFactory.TIMES_BOLD,14,BaseColor.BLACK)));
table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
}
table2.setWidthPercentage(100);
document.add(table2);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
document.close();
String pdfFile="D:\\PURCHASEORDER\\"+see+".pdf";
File f = new File(pdfFile);
if (pdfFile.toString().endsWith(".pdf")) {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + pdfFile);
} else {
//For cross platform use
Desktop desktop = Desktop.getDesktop();
desktop.open(f);
}
Java에서 제공하는 PreparedStatement 및 ResultSet 클래스를 사용해 본 적이 있습니까? – Aaron
네, 이미 알고 있습니다. 내가 알지 못하는 부분은 각 결과 집합이 각 열에 삽입된다는 것을 어떻게 표시 할 수 있는지입니다. –