我用实现的“ iText”库和一个主类制作了自己的javafx库“ GeneratingPDF”:
public class Main {
public static void main(String[] args) {
try {
String file_name = "Client_list.pdf";
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(file_name));
document.open();
Paragraph para = new Paragraph("List of clients: \n\n\n");
document.add(para);
if(args.length > 0){
for(String arg : args) {
document.add(new Paragraph(arg));
System.out.println("Arg added");
}
}
document.close();
}catch (Exception e) {
System.err.println(e);
}
}
}
此库获取参数列表,并从中生成PDF文档。我还有另一个带有按钮“ Generate Raport”和下面粘贴的onAction方法的javafx项目。我已经将我的库添加到项目中。我想从数据库中检索客户信息,并将其发送到我的图书馆,该图书馆将生成PDF文件。我应该在此方法中添加什么?如何在代码中使用我自己的“ GeneratingPDF.jar”库?
public void generateRaport(ActionEvent actionEvent) {
try {
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/projekt_zespolowe?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "");
PreparedStatement ps = null;
ResultSet rs = null;
String query="SELECT * FROM client";
ps=connection.prepareStatement(query);
rs=ps.executeQuery();
while(rs.next()){
//(rs.getString("client_id")+ " "+rs.getString("login")+ " "+rs.getString("name")+ " "+rs.getString("surname")+ " "+rs.getString("date_birth")+ " "+rs.getString("city"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}