Archive for October, 2007

Jasperreports in Jmatter

Wednesday, October 31st, 2007

This is my answer to one of the question in groups.google.com/group/jmatter
here is how i used jasperreports + ireport + Jmatter
i have kept it step wise so that it is easy to follow
please visit my  blog at http://CodeWithMe.com/blog for the screen shots
i will post it after few days and email me at justniraj at hotmail dot com if you think i can answer you

Step 1) Make a EO Class
in my case the EO class is

package com.quickresource.models;
import com.u2d.element.CommandInfo;
import com.u2d.model.AbstractComplexEObject;
import com.u2d.model.ComplexType;
import com.u2d.model.Title;
import com.u2d.persist.Persist;
import com.u2d.reflection.Cmd;
import com.u2d.type.atom.StringEO;

@Persist
public class SampleEO extends AbstractComplexEObject {
private final StringEO name = new StringEO();

private final StringEO age = new StringEO();

@Override
public Title title() {
return new Title(”TEst”);
}

public StringEO getAge() {
return age;
}

public StringEO getName() {
return name;
}

}

Step 2)
build your jmatter project
what i mean is generate the class files for your EO classes

Step 3)
open ireport set the classpath by following menu options
add
build/classes directory of your jmatter application to the classpath of ireport
add
jmatter.jar , jibx-extras.jar, jibx-run.jar of your lib/runtime directory to the classpath of ireport

Step 3)
Open a new Report
Follow the menu
data->report query

Step 4)
Instead of Report Query where you write the sql choose Java bean datasource

Step 5)
give fully qualified name of your EO object
in my case :
com.quickresource.models.SampleEO

Step 6)
now you will get the filed name and age in the property box of ireport you can design the report as normal ireport report
but remember the class of the field(s) is com.u2d.type.atom.StringEO

Step 7)
Compile the report you cannot preview the report with live data as you are not using any live datbase

Step 8)
copy the generated .jaseper file to you application directory in my case i copied the file sampleReport.jasper to
/com/quickresource/models/ of my src dir

Step 9)
Copy the libs(jars) needed for jasper report
now here is the easy way to do
although you can get the jasper report from the jasper report project what i like to do is
copy following folders from lib of springframe work to /lib/runtime of my application
folders i copied
1) jakarta-commons
Required jar files by jasper report
2) jasperreports
Jasper report jar files

you do not need to change the build.xml of jmatter as it is set to include all the sub directories of /lib/runtime

Step 10)
now add the following code to you EO class
@Cmd
public static Object printAllEmployee(CommandInfo info) {
try {
List list = ComplexType.forClass(SampleEO.class).list().getItems();
JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(
list);
JasperPrint print = JasperFillManager
.fillReport(SampleEO.class.getResourceAsStream(”/com/quickresource/models/sampleReport.jasper”),null, datasource);

JRViewer viewer = new JRViewer(print);
return viewer;

} catch (Exception ms) {
ms.printStackTrace();
return null;
}
}


Step 11)
add SampleEo to your classbar
now compile and run right click on the SampleEOs of Class bar
you will be able to see jasper report preview in jmatter screen
Thats it
Have fun jmatter matters a lot

Here is the complete code listing

1) com/quickresource/models/SampleEO.java

package com.quickresource.models;

import java.util.List;

import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JRViewer;

import com.u2d.element.CommandInfo;
import com.u2d.model.AbstractComplexEObject;
import com.u2d.model.ComplexType;
import com.u2d.model.Title;
import com.u2d.persist.Persist;
import com.u2d.reflection.Cmd;
import com.u2d.type.atom.StringEO;

@Persist
public class SampleEO extends AbstractComplexEObject {
private final StringEO name = new StringEO();

private final StringEO age = new StringEO();

@Override
public Title title() {
return new Title(”TEst”);
}

public StringEO getAge() {
return age;
}

public StringEO getName() {
return name;
}

@Cmd
public static Object printAllEmployee(CommandInfo info) {
try {
List list = ComplexType.forClass(SampleEO.class).list().getItems();
JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(
list);
JasperPrint print = JasperFillManager
.fillReport(
SampleEO.class
.getResourceAsStream(”/com/quickresource/models/sampleReport.jasper”),
null, datasource);

JRViewer viewer = new JRViewer(print);
return viewer;

} catch (Exception ms) {
ms.printStackTrace();
return null;
}
}

}

2) SampleReport.jxml(as genereated by jasper report)
<?xml version=”1.0″ encoding=”UTF-8″  ?>
<!– Created with iReport - A designer for JasperReports –>
<!DOCTYPE jasperReport PUBLIC “//JasperReports//DTD Report Design//EN” “http://jasperreports.sourceforge.net/dtds/jasperreport.dtd”>
<jasperReport
name=”sampleReport”
columnCount=”1″
printOrder=”Vertical”
orientation=”Portrait”
pageWidth=”595″
pageHeight=”842″
columnWidth=”535″
columnSpacing=”0″
leftMargin=”30″
rightMargin=”30″
topMargin=”20″
bottomMargin=”20″
whenNoDataType=”NoPages”
isTitleNewPage=”false”
isSummaryNewPage=”false”>
<property name=”ireport.scriptlethandling” value=”0″ />
<property name=”ireport.encoding” value=”UTF-8″ />
<import value=”java.util.*” />
<import value=”net.sf.jasperreports.engine.*” />
<import value=”net.sf.jasperreports.engine.data.*” />

<field name=”age” class=”com.u2d.type.atom.StringEO”>
<fieldDescription><![CDATA[age]]></fieldDescription>
</field>
<field name=”name” class=”com.u2d.type.atom.StringEO”>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>

<background>
<band height=”0″  isSplitAllowed=”true” >
</band>
</background>
<title>
<band height=”50″  isSplitAllowed=”true” >
</band>
</title>
<pageHeader>
<band height=”50″  isSplitAllowed=”true” >
<staticText>
<reportElement
x=”208″
y=”18″
width=”131″
height=”18″
key=”staticText-1″/>
<box topBorder=”None” topBorderColor=”#000000″ leftBorder=”None” leftBorderColor=”#000000″ rightBorder=”None” rightBorderColor=”#000000″ bottomBorder=”None” bottomBorderColor=”#000000″/>
<textElement>
<font/>
</textElement>
<text><![CDATA[Page Header of Sample]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height=”30″  isSplitAllowed=”true” >
<staticText>
<reportElement
x=”6″
y=”6″
width=”97″
height=”17″
key=”staticText-2″/>
<box topBorder=”None” topBorderColor=”#000000″ leftBorder=”None” leftBorderColor=”#000000″ rightBorder=”None” rightBorderColor=”#000000″ bottomBorder=”None” bottomBorderColor=”#000000″/>
<textElement>
<font/>
</textElement>
<text><![CDATA[age]]></text>
</staticText>
<staticText>
<reportElement
x=”232″
y=”8″
width=”106″
height=”18″
key=”staticText-3″/>
<box topBorder=”None” topBorderColor=”#000000″ leftBorder=”None” leftBorderColor=”#000000″ rightBorder=”None” rightBorderColor=”#000000″ bottomBorder=”None” bottomBorderColor=”#000000″/>
<textElement>
<font/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height=”18″  isSplitAllowed=”true” >
<textField isStretchWithOverflow=”false” isBlankWhenNull=”false” evaluationTime=”Now” hyperlinkType=”None”  hyperlinkTarget=”Self” >
<reportElement
x=”2″
y=”0″
width=”100″
height=”18″
key=”textField”/>
<box topBorder=”None” topBorderColor=”#000000″ leftBorder=”None” leftBorderColor=”#000000″ rightBorder=”None” rightBorderColor=”#000000″ bottomBorder=”None” bottomBorderColor=”#000000″/>
<textElement>
<font/>
</textElement>
<textFieldExpression   class=”java.lang.String”><![CDATA[”"+$F{age}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow=”false” isBlankWhenNull=”false” evaluationTime=”Now” hyperlinkType=”None”  hyperlinkTarget=”Self” >
<reportElement
x=”234″
y=”0″
width=”100″
height=”18″
key=”textField”/>
<box topBorder=”None” topBorderColor=”#000000″ leftBorder=”None” leftBorderColor=”#000000″ rightBorder=”None” rightBorderColor=”#000000″ bottomBorder=”None” bottomBorderColor=”#000000″/>
<textElement>
<font/>
</textElement>
<textFieldExpression   class=”java.lang.String”><![CDATA[”"+$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height=”30″  isSplitAllowed=”true” >
</band>
</columnFooter>
<pageFooter>
<band height=”50″  isSplitAllowed=”true” >
</band>
</pageFooter>
<lastPageFooter>
<band height=”50″  isSplitAllowed=”true” >
</band>
</lastPageFooter>
<summary>
<band height=”50″  isSplitAllowed=”true” >
</band>
</summary>
</jasperReport>

Text to image in Java

Tuesday, October 16th, 2007

package com.sajilo.examples;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.servlet.*;
import javax.servlet.http.*;

public class Text2Image extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(”image/png”);
OutputStream out = response.getOutputStream();
try {
String text = request.getParameter(”text”);
String colorCode = request.getParameter(”color”);
String fontName = request.getParameter(”font”);
int width = text.length() * 20;
BufferedImage image = new BufferedImage(width, 40, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.WHITE);
g.fillRect(0, 0, 400, 400);
/*
should me able to create the font from the device too
// Font tempFont=Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(”c:\\windows\\fonts\\BLUEHIGH.ttf”));

also i have kept 20 which can be determined by using fontcontext */
Font useFont = new Font(fontName, Font.BOLD, 20);
g.setFont(useFont);
g.setColor(new Color(Integer.parseInt(colorCode, 16)));
g.drawString(text, 10, 20);

ImageIO.write(image, “png”, out);
} catch (Exception ms) {
ms.printStackTrace();
}

finally {

out.close();
}
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}

public String getServletInfo() {
return “Servlet to convert the text into image”;
}

}

======================end===============
after mapping servlet as  Text2Image the image can be generated in jsp or html files as
<img src=”Text2Image?text=This is fun&color=ff0000&font=PCS NEPAL”/>

Text to image in PHP

Monday, October 15th, 2007

want to show some cool font rendered as image to the client
here is sample code of how you can using GD in PHP
save the below code as text2image.php

==========text2image.php============
<?
$text=stripslashes($to_image);
$text=ucwords($text);
$temp_color=$color;
$r= hexdec( substr($temp_color,0,2));
$g=hexdec( substr($temp_color,2,2));
$b=hexdec( substr($temp_color,4,2));
header(”Content-type: image/png”);
$fonte=”path_to_font_dir/”.$font.”.ttf”;
$bbox = imagettfbbox($size,0,$fonte,$text);
$x_size = abs($bbox[4] - $bbox[0]);
$y_size = abs($bbox[5] - $bbox[1]);
$width=$x_size+5 ;
$im = imagecreatetruecolor($width, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$red=imagecolorallocate($im,$r,$g,$b);
//$string = “This is some text..”;
imagealphablending($im,true);
imagefill($im,0,0,$white);
imagettftext($im,$size/75*72, 0, 5, 21, $red, $fonte, $text);
imagepng($im);
imagedestroy($im);
?>

not from any HTML page or PHP page simple
call
<img src=”text2image.php?font=SomeFontAvailableInServer&to_image=text to display&color=ff0000″ alt=”image rendered at server”>

Text Scrolling after mouse

Monday, October 15th, 2007

This one is a cool java App that shows text scrolling behind mouse with out any fliker
move the mouse and drag to exit.
This mouse effect was popular in Flash and javascript webpages
I just wrote it for fun as there is a loud voice over filthy rich client

TestLogic.java
============

import java.awt.AlphaComposite;

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

import javax.swing.ImageIcon;
import javax.swing.JWindow;

public class TestLogic extends JWindow implements MouseMotionListener, Runnable {

public static void main(String sd[]) {
TestLogic l = new TestLogic();
GraphicsEnvironment en = GraphicsEnvironment
.getLocalGraphicsEnvironment();
en.getDefaultScreenDevice().setFullScreenWindow(l);
l.setVisible(true);
Thread tx = new Thread(l);
tx.start();

}

clip clips[];
int x, y;
String data = “Move to See and drag to exit”.toUpperCase();
BufferedImage toPaint;
public TestLogic() {

this.toPaint = new BufferedImage(1500, 1500, BufferedImage.TYPE_INT_RGB);
char c[] = data.toCharArray();
clips = new clip[c.length];
int counter = 0;

for (char ca : c) {
clips[counter] = new clip();
clips[counter].x = 0;
clips[counter].y = 0;
clips[counter].spot = “” + ca;
counter++;
}
this.addMouseMotionListener(this);

}

public void mouseDragged(MouseEvent e) {
System.exit(1);
}

public void mouseMoved(MouseEvent e) {
this.x = e.getX();
this.y = e.getY();
System.out.println(this.x);

}
public void run() {
try {
plotScape();
} catch (Exception ms) {
ms.printStackTrace();
}

}

int hunter = 0;

int konstant = 0;

public void plotScape() throws InterruptedException {

for (int counter = clips.length - 1; counter > 0; counter–) {

clips[counter].x = clips[counter - 1].x+20;
clips[counter].y = clips[counter - 1].y;
}

clips[0].x = this.x;
clips[0].y = this.y;
Thread.sleep(50);
repaint();
plotScape();

}

public void paint(Graphics gaa) {
Graphics2D g = (Graphics2D) gaa;
Graphics2D grap = (Graphics2D) this.toPaint.getGraphics();
grap.setColor(Color.WHITE);
grap.fillRect(0, 0, 1500, 1500);
grap.setFont(new Font(”Courier New”, Font.BOLD, 40));
grap.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
grap.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
grap.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
for (clip ca : clips) {
ca.paint(grap);
}
g.drawImage(this.toPaint, 0, 0, this);

}

}

class clip {
int x;

int y;

String spot;

public void paint(Graphics2D graph) {
graph.setColor(Color.BLACK);
graph.drawString(spot, x, y);
graph.setColor(Color.WHITE.darker());
graph.drawString(spot, x+2, y+2);

}
}

Something that is not yet answered

Sunday, October 14th, 2007

I faced a problem regarding Jruby and javax.sound API
and posted the commented here and again here but i have not got any solutions yet
please help me if you can slove this one .

and this one is also some thing that has not been solved well i conclude that this is not done in java please look in to and answer me am i right ?

Reflection…. new Instance in C#, ActionScript 3 , Java , Ruby and PHP

Sunday, October 14th, 2007

ok this one is getting type out of the string as we do in java

String dString=”java.util.Date”;
Class dClass=Class.forName(dString);
java.util.Date dt=dClass.newInstance();

And now in c#

String dString=”System.DateTime”;
Type dType=Type.GetType(dString);
DateTime dt=Activator.CreateInstance(dType);

And this one in Ruby

require “date”
dString=”Date”
dClass=Kernel.const_get(dString)
dt=dClass.new
puts dt

this one in Action script 3

var dString:String=”Date”;
var dClass=flash.utils.getDefinationByName(dString);
dt=new dClass();
trace(dt);

this one in PHP
$dStr=”SomeClass”;
$dObject=new $dStr();

So which one is easier ?

AMFPHP and actionscript 3

Saturday, October 13th, 2007

I am writing an online multiplayer card game that uses AMFPHP and Flash actionscript 9. Here goes the code that connects Actionscript 3 with AMFPHP. I am writing it step wise so that it may help beginners.
1) Step no 1
develop a service class in PHP and place the class at the services folder of the AMFPHP
my code goes here

=======games/Gameservice.php========
class GameService

{
function getVersion()

{
return “1.1″;
}

function getArrayWithParameter($a,$b)
{
$arr=array();
$arr[0]=$a;
$arr[1]=$b;
$arr[2]=$a+$b;
return $arr;
}

}

2) Step no 2 In action script 3
var conn:NetConnection=new NetConnection();
var resultArray:Array;
var responder:Responder=new Responder(onResult,onError);
function onResult(arr:Array)
{
resultArray=arr;

test();

}

function onError(err:Error)
{
trace(err.description);
}
conn.connect(”http://localhost/amfphp/gateway.php”);
conn.call(”games.Gameservice.getArrayWithParameter”,responder,12,122);
//here 12 and 122 are the arguments

function test()

{

trace(resultArray[3]);

//output is 134

}
}

Url Variable in Action script 3

Friday, October 12th, 2007

Thing were easy in Actionscript 2 when you need to pass value from browser to the flash the you could do

  <object classid=“clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″
 codebase=“http://download.macromedia.com/
pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0″ width=“210″ height=“120″>

    <param name=“movie” value=“aflash.swf?var1=value1&var2=value2″>

    <param name=“quality” value=“high”>

    <param name=“wmode” value=“transparent”>

    <param name=“menu” value=“false”>

    <embed src=aflash.swf?var1=value1&var2=value2

width=“210″ height=“120″ quality=“high” 
pluginspage=“http://www.macromedia.com/go/getflashplayer” 
type=“application/x-shockwave-flash” wmode=“transparent” menu=“false”></embed>

Here i am passing two variable var1 and var2
in actionscript i can just refer the variables as var1 and var2 in the main time line or the time line of _root
but in Action script 3 the code goes like this
(Code in the main time line)

var1=this.loaderInfo.parameters.var1;

What is loaderInfo ?
loaderInfo is an object of flash.display.LoaderInfo . It provides information about loaded media such as content type, content length, url , bytesloaded
The Class DisplayObject has a property loaderInfo of type LoderInfo which means all the classes like movieclip, buttons (sub classes of Displaybjet) have this property so does the main time line . so we are using parameters property to get url variable .

no _root in Actionscript 3

Friday, October 12th, 2007

Hey we don’t have _root in ActionScript 3
annoying is it well here is what AS3 has for _root
1) Stage
The Stage class in flash.display package represents the drawing area of the main stage and stage is the ready made object of the Stage so now if you want to put an instance of a movie clip Abc then the code would be

var aClip:Abc=new Abc();
stage.addChild(aClip);

2) this in main time line
this referred to the _root in Action script 2 when you use it in main time line but in Actionscript 3 this refers to the object of MainTimeLine which also extends the class flash.display.DisplayObject

Generate dynamic report in Jasper Report

Friday, October 12th, 2007

I like and use Jasper Report
I have used JFree Report but due to the lack of designing look like Ireport and Jasper Pal i prefer Jasper Report for reporting in java. Eclipse based Brit Report is also available but have not tried yet.

You can make dynamic Reports in Jasper Report .
I am not talking about changing the value of the parameters $P{} but i am talking about generating a report design in runtime.

You can do this in two ways

Jasper Report keeps its design in xml format which has common extension of .jrxml
you can write program using DOM to prepare a valid XML document to fit as a jasper report design and compile that using Jasper compiler.

Another is by preparing the report by coding and the example of the code is here

package dynaReport;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JRAlignment;
import net.sf.jasperreports.engine.JRBand;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.design.JRDesignExpression;
import net.sf.jasperreports.engine.design.JRDesignField;
import net.sf.jasperreports.engine.design.JRDesignStaticText;
import net.sf.jasperreports.engine.design.JRDesignTextElement;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;

public final class DynaReport {

public DynaReport() {

}

public final JasperDesign getPreMatureDesign(
java.sql.ResultSetMetaData data, int ColumnWidth, int reportWidth,
int reportHeight, int gap, boolean landSacpe) throws JRException,
SQLException {
JasperDesign design = (JasperDesign) JRXmlLoader.load(”./design.jrxml”);
System.out.println(design.getOrientation());
if (landSacpe) {
design.setOrientation((byte) (0));
}
design.setPageWidth(reportWidth);
design.setPageHeight(reportHeight);
Map designFieldMap = (HashMap) design.getMainDesignDataset()
.getFieldsMap();
JRBand bandDetail = design.getDetail();
bandDetail.setSplitAllowed(false);
List bandDetailList = bandDetail.getChildren();

JRBand columnHeader = design.getColumnHeader();
List columnHeaderList = (ArrayList) columnHeader.getChildren();
List designFieldList = (ArrayList) design.getMainDesignDataset()
.getFieldsList();

JRDesignStaticText[] staticFields = this.getHeaders(data, ColumnWidth);
JRDesignTextField[] texts = this.getDataSet(data, designFieldMap,
bandDetailList, designFieldList, ColumnWidth);
int x = 0;
int xHeader = 0;
int counter = 0;
for (JRDesignTextField temp : texts) {
staticFields[counter].setX(xHeader);
temp.setX(x);
columnHeaderList.add(staticFields[counter]);

x += ColumnWidth;
if (counter != 0) {
x += gap;
}
xHeader += ColumnWidth;
counter++;

}
return design;
}

private final JRDesignStaticText[] getHeaders(ResultSetMetaData data,
int width) throws SQLException {
int columnCount = data.getColumnCount();
JRDesignStaticText texts[] = new JRDesignStaticText[columnCount];
for (int counter = 1; counter <= columnCount; counter++) {
texts[counter - 1] = new JRDesignStaticText();
texts[counter - 1].setText(data.getColumnName(counter).replace(”_”,
” “));
texts[counter - 1]
.setHorizontalAlignment(JRDesignTextElement.HORIZONTAL_ALIGN_CENTER);
texts[counter - 1].setKey(”staticText-” + counter);
texts[counter - 1].setBold(true);
texts[counter - 1].setMode(JRDesignStaticText.MODE_OPAQUE);
texts[counter - 1].setPdfFontName(”PCS NEPALI”);
texts[counter - 1].setFontName(”SanSerif”);
texts[counter - 1].setFontSize(10);
texts[counter - 1].setWidth(width);
texts[counter - 1].setHeight(30);
texts[counter - 1].setY(0);
}
return texts;

}

private final JRDesignTextField[] getDataSet(ResultSetMetaData data,
Map designFieldMap, List bandDetailList, List designFieldList,
int width) throws SQLException {
int columnCount = data.getColumnCount();
JRDesignTextField fields[] = new JRDesignTextField[columnCount];

for (int counter = 1; counter <= columnCount; counter++) {
fields[counter - 1] = new JRDesignTextField();
String field_name = data.getColumnName(counter);

bandDetailList.add(fields[counter - 1]);

JRDesignField designField = new JRDesignField();

designField.setName(field_name);

// designField.setValueClassName();
designField.setValueClassName(”java.lang.String”);
designFieldList.add(designField);
designFieldMap.put(field_name, designField);

JRDesignExpression exp = new JRDesignExpression();
exp.setValueClassName(”java.lang.String”);
exp.setText(”$F{” + field_name + “}”);

fields[counter - 1].setExpression(exp);
fields[counter - 1].setKey(”textField-” + counter);
fields[counter - 1].setBlankWhenNull(true);
fields[counter - 1].setHeight(20);
fields[counter - 1].setWidth(width);
fields[counter - 1].setY(0);
fields[counter - 1].setFontName(”PCS NEPAL”);
if (data.getColumnClassName(counter).equalsIgnoreCase(
“java.math.BigDecimal”)) {
fields[counter - 1]
.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
} else {
fields[counter - 1]
.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);
}

}
return fields;

}

}

Get the result set meta data from the result set of the sql
like select a,b,c from Tab1 will get u report with 3 fields