Testing the invoice database

This is a code example of iText PDF, discover more.

30th August 2015
admin-marketing

Switch code for this example

In the examples stored under ZUGFeRD: POJOs for our simple invoice database, we create the infrastructure to query an invoice database.

This example will use this infrastructure to test if the database can be accessed and if the POJOs give us access to all the data we need.

The output of this test example looks like this:

Invoice id: 4 Date: 2015-04-01 Total cost: 1507.0€
Customer: 30
    First Name: Bill
    Last Name: Sommer
    Street: 362 - 20th Ave.
    City: BE 9000 Ghent
  #0  (28)   Running jersey      8.0€   vat 21.0%  Quantity: 9  Cost: 72.0€
  #1  (35)   Golf polo           8.0€   vat 21.0%  Quantity: 1  Cost: 8.0€
  #2  (41)   Threadmill          600.0€ vat 21.0%  Quantity: 2  Cost: 1200.0€
  #3  (23)   Pro steel dartboard 25.0€  vat 21.0%  Quantity: 2  Cost: 50.0€
  #4  (9)    My First Cookbook   17.0€  vat 6.0%   Quantity: 1  Cost: 17.0€
  #5  (37)   Golf kit            80.0€  vat 21.0%  Quantity: 2  Cost: 160.0€


DatabaseTest.java
  1. /*
  2.  * This example was written by Bruno Lowagie
  3.  */
  4. package zugferd;
  5.  
  6. import java.sql.SQLException;
  7. import java.util.List;
  8.  
  9. import zugferd.pojo.Invoice;
  10. import zugferd.pojo.PojoFactory;
  11.  
  12. /**
  13.  * A simple example to test the database
  14.  */
  15. public class DatabaseTest {
  16.     public static void main(String[] args) throws SQLException {
  17.         PojoFactory factory = PojoFactory.getInstance();
  18.         List invoices = factory.getInvoices();
  19.         for (Invoice invoice : invoices)
  20.             System.out.println(invoice.toString());
  21.         factory.close();
  22.     }
  23. }

Resources

Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now