質問データベースからデータが取得され、scrollPane に埋め込まれた JTable オブジェクト「テーブル」に表示されたら、表示されたテーブルをそのまま A3 サイズの用紙に印刷できる印刷ジョブを作成するにはどうすればよいですか?
データベースからデータを取得するための私のコードを以下に示します。
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/newb","root","pass");
Statement stat=con.createStatement();
ResultSet res=stat.executeQuery("select * from table where name = '"+name+"'");
ResultSetMetaData rsmd = res.getMetaData();
int colcount = rsmd.getColumnCount();
Vector columns = new Vector(colcount);
for(int i=3; i<=colcount; i++)
{
columns.add(rsmd.getColumnName(i));
}
Vector data = new Vector();
Vector row;
// Store row data
while(res.next())
{
row = new Vector(colcount);
for(int i=3; i<=colcount; i++)
{
row.add(res.getString(i));
}
data.add(row);
}
table = new JTable(data, columns);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.setViewportView(table);
}
catch(Exception ex)
{
System.out.println(ex);
}
テーブルからデータを取得するためにベクター クラスを使用しています。表示された表に示されているデータをどのように紙に出力しますか?