/* * DynamicJasper: bibliothèque permettant de créer dynamiquement des rapports en spécifiant * colonnes, groupes, styles, etc. lors de l'exécution. Il sauve aussi beaucoup de développement * temps dans de nombreux cas! (http://sourceforge.net/projects/dynamicjasper) * * Copyright (C) 2008 FDV Solutions (http://www.fdvsolutions.com) * * Cette bibliothèque est un logiciel libre; vous pouvez le redistribuer et/ou le modifier * le modifier selon les termes du GNU Lesser General Public * * Licence telle que publiée par la Free Software Foundation; soit * * version 2.1 de la licence, soit (selon votre choix) toute version ultérieure. * * Cette bibliothèque est distribuée dans l'espoir qu'elle sera utile, * mais SANS AUCUNE GARANTIE; sans même la garantie implicite de * * QUALITÉ MARCHANDE ou D'ADAPTATION À UN USAGE PARTICULIER. Voir le GNU * * Lesser General Public License pour plus de détails. * * Vous devriez avoir reçu une copie de la licence GNU Lesser General Public * avec cette bibliothèque; sinon, écrivez à la Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * */Comment envoyer un attribut de la base de données à dJ pour créer un rapport
package ar.com.fdvs.dj.test;
import java.sql.*;
import java.awt.Color;
import java.util.Date;
import java.util.Locale;
import net.sf.jasperreports.view.*;
import ar.com.fdvs.dj.domain.AutoText;
import ar.com.fdvs.dj.domain.DynamicReport;
import ar.com.fdvs.dj.domain.Style;
import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
import ar.com.fdvs.dj.domain.builders.StyleBuilder;
import ar.com.fdvs.dj.domain.constants.Font;
import ar.com.fdvs.dj.core.DJConstants;
// import ar.com.fdvs.dj.test.*;
public class Main extends BaseDjReportTest {
publique DynamicReport buildReport() throws Exception { // Connexion C = nouvelle connexion(); // C.Con(); CConnection C = nouveau CConnection(); C.Connection(); Déclaration stmt; ResultSet rs = null; String SQL = "SELECT * FROM étudiant"; stmt = C.Con(). CreateStatement(); rs = stmt.executeQuery (SQL); Chaîne res = "";
FastReportBuilder drb = new FastReportBuilder();
drb.setQuery(SQL, DJConstants.QUERY_LANGUAGE_SQL);
while (rs.next()){
res= rs.getString("Name");
**drb.addColumn("Name","Name", String.class.getName(),30);**
// drb.addc
}
//.addColumn("Branch", "branch", String.class.getName(),30)
// .addColumn("Item", "item", String.class.getName(),50)
// .addColumn("Item Code", "id", Long.class.getName(),30,true)
// .addColumn("Quantity", "quantity", Long.class.getName(),60,true)
// .addColumn("Amount", "amount", Float.class.getName(),70,true)
drb.addGroups(2);
DynamicReport sa =drb.build();
drb.setSubtitle("This report was generated at " + new Date())
.setTemplateFile("templates/TemplateReportTest.jrxml")
.setUseFullPageWidth(true);
Style atStyle = new StyleBuilder(true).setFont(Font.COMIC_SANS_SMALL).setTextColor(Color.red).build();
Style atStyle2 = new StyleBuilder(true).setFont(new Font(9, Font._FONT_TIMES_NEW_ROMAN, false, true, false)).setTextColor(Color.BLUE).build();
/***
* Adding many autotexts in the same position (header/footer and aligment) makes them to be one on top of the other
*/
//First add in the FOOTER
drb.addAutoText(AutoText.AUTOTEXT_PAGE_X, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200,40, atStyle);
drb.addAutoText("Autotext below Page counter", AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT);
//Note the styled text: <b>msimone</b>, valid tags are: <b>, <i> and <u>
drb.addAutoText("Created by <b>msimone</b>", AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT,200);
drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT,30,30,atStyle2);
drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT,AutoText.PATTERN_DATE_DATE_TIME);
//Now in HEADER
drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,100,40);
drb.addAutoText("Autotext at top-left", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200);
drb.addAutoText("Autotext at top-left (2)", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200);
drb.addAutoText("Autotext at top-center", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_CENTER,200,atStyle);
// DynamicReport dr = drb.build();
//i18N, you can set a Locale, different tha n the default in the VM
drb.setReportLocale(new Locale("es","AR"));
drb.setReportLocale(new Locale("pt","BR"));
drb.setReportLocale(new Locale("fr","FR"));
return sa;
}
public static void main(String[] args) throws Exception {
**Main test = new Main();
test.testReport();**
JasperViewer.viewReport(test.jp);
JasperDesignViewer.viewReportDesign(test.jr);
//JasperDesignViewer.viewReportDesign(DynamicJasperHelper.generateJasperReport(test.dr, test.getLayoutManager(),new HashMap()));
}
}
La rédaction de ce im code obtenir exception suivante et je ne peux pas vraiment comprendre la raison
Exception dans le thread "principal" net.sf.jasperreports .engine.JRException: Erreur lors de la récupération de la valeur du champ à partir de bean: varchar sur net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty (JRAbstractBeanDataSource.java:123) à net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue (JRAbstractBeanDataSource.java:96) à net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue (JRBeanCollectionDataSource.java:100) à net.sf. jasperreports.engine.fill.JRFillDataset.setOldValues (JRFillDataset.java:818) à net.sf.jasperreports.engine.fill.JRFillDataset.next (JRFillDataset.java:782) à net.sf.jasperreports.engine.fill. JRBaseFiller.next (JRBaseFiller.java:1448) à net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport (JRVerticalFiller.java:108) à net.sf.jasperreports.engine.fill.JRBaseFiller.fill (JRBaseFiller.java:923) à net.sf.jasperreports.engine.fill.JRBaseFiller.fill (JRBaseFiller.java:845) à net.sf.jasperreports.engine.fill.JRFiller.fillReport (JRFiller. java: 85) à net.sf.jasperreports.engine.JasperFillManager.fillReport (JasperFillManager.java:624) à ar.com.fdvs.dj.test.BaseDjReportTest.testReport (BaseDjReportTest.java:93) à ar. com.fdvs.dj.test.Main.main (Main.java:121) Causé par: java.lang.NoSuchMethodException: propriété inconnue 'varchar' sur la classe 'classe ar.com.fdvs.dj.test.domain.Product ' à org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty (PropertyUtilsBean.java:1322) à org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty (PropertyUtilsBean.java:770) à org.apache.commons.beanutils.PropertyUtilsBean.getProperty (PropertyUtilsBean.java:846) à org.apache.commons.beanutils.PropertyUtils.getProperty (PropertyUtils.java:426) à net.sf.jasperreports.engine. data.JRAbstractBeanDataSource.getBeanProperty (JRAbstractBeanDataSource.java:111) ... 12 plus Java Résultat: 1