Problem in java.awt.print

Hi here is my code .

I am generating page dynamically and passing to printer.

Printing Functionalities working file. But I am taking some data from database (Access). And in this code for example i have 4 records in Database and i am generating 4 pages (each page for resord).

I am getting only 2 records. And for other two records i am getting blank page.

Reason is My ResultSet object is moving to next record twice.

I mean if i have 6 records i get only 3 pages.

If i have 10 records i get only 5 pages and If i have 1 record i dont get any page.

How shall i solve this problem.

Thanx in advance.

import java.awt.*;

import java.awt.print.*;

import java.sql.*;

public class SubbuBook extends Thread implements Printable {

Connection con;

Statement stmt;

static ResultSet rsValue;

public void run() {

dataConnection();

PrinterJob job = PrinterJob.getPrinterJob();

Book bk = new Book();

job.setPageable(bk);

if (job.printDialog()) {

try {

bk.append(new SubbuBook(),job.defaultPage(), 4);

job.print();

}catch (Exception e) {

System.out.println("Exception "+e);

}

}

System.exit(0);

}

public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {

Font fntHeading = new Font("Helvetica",Font.BOLD,24);

Font fntRow = new Font("Helvetica",Font.PLAIN,14);

try{

if(rsValue.next()) {

g.setFont(fntHeading);

g.setColor(Color.red);

g.drawString("Main Report",200,100);

g.setColor(Color.blue);

g.drawLine(100,150,500,150);

g.drawLine(100,150,100,500);

g.drawLine(100,500,500,500);

g.drawLine(500,100,500,500);

g.drawLine(200,150,200,500);

g.setFont(fntRow);

g.setColor(Color.black);

g.drawString("Program Id",120,200);

g.drawString(rsValue.getString("prog_id"),250,200);

g.drawString("Program Name",120,250);

g.drawString(rsValue.getString("prog_name"),250,250);

g.drawString("Artist Name",120,300);

g.drawString(rsValue.getString("Artist"),250,300);

}

}catch(Exception ae) {

System.out.println("Exception inside Paint"+ae);

}

return Printable.PAGE_EXISTS;

}

private void dataConnection() {

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:artist");

stmt=con.createStatement();

rsValue=stmt.executeQuery("select * from artist order by Prog_name");

System.out.println("Connection is Proper");

}catch(Exception e){

System.out.println("Exception at Connection"+e);

}

}

}

[2775 byte] By [subhaskumar] at [2007-9-26 23:51:08]
# 1
I am not sure this..Instead of if pls give while and check:try{while(rsValue.next()) { g.setFont(fntHeading); g.setColor(Color.red); g.drawString("Main Report",200,100); -
cini_gm at 2007-7-4 14:06:05 > top of Java-index,Archived Forums,Java Programming...
# 2
thanx Cini,That will not solve my problem.Becs my print method will call automatically 4 times (if i have 4 records).And i cannot put while loop inside that.Thanx
subhaskumar at 2007-7-4 14:06:05 > top of Java-index,Archived Forums,Java Programming...