Java  & MySQL, Printing

Posted on 2004-11-15
Last Modified: 2006-11-17
Hi Experts,

I have a MySQL table which I have written a Java Application to add, navigate and (am currently working on) delete records. However, I would also like to add print function but am unsure how to do this.

Image I have a table wtih 4 fields:

User_First _Name

I understand how to create an SQL query to find the relevant records requested. My problem is 2 fold but associated:

1. How do I ensure that the output when it is printed does not scroll off the end of my screen, for example, if My screen could display say 50 lines and the number of records returned was 75, how could I stop the page from scrolling off after line 51?
2. How do I create a report in Java, perhaps with a print preview option, with the same critieria as #1, i.e make sure the report stays on the page and has headers and footers etc.?

I'm guessing these should be possible but I cannot find anything on this on the net so would be grateful for any advice, links or whatever.

Question by:MushyPeeze
    LVL 1

    Accepted Solution

    I suggest you use JFreeReport:

    It is quite easy to create a report that way with headers and footers. You can also easily have a print preview. I already used this in a project of mine.

    Another option is to convert your output to XML, then do an XSLT-FO transformation and use FOP to create a PDF. You can then use Acrobat Reader as print preview. But I would not recommend this option since you're not starting from XML anyway.

    Expert Comment

    why don't you control what will be displayed by limiting number of rows that mysql will return, i.e.:

    SELECT * FROM workers LIMIT 50 OFFSET 0;
    SELECT * FROM workers LIMIT 50 OFFSET 50;
     . . .

    LVL 4

    Expert Comment

    Jasper is also a good alternative.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    twoTwo  challenge 35 71
    factorial example challenge 10 44
    count11 challenge 6 32
    solarwind tftp server 2 18
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now