/* * DynamicJasper: 実行時に列、グループ、スタイルなどを指定してレポートを動的に作成する * ライブラリ。また、多くの場合、開発時間を大幅に節約できます! ( http://sourceforge.net/projects/dynamicjasper ) * * Copyright (C) 2008 FDV Solutions ( http://www.fdvsolutions.com) * * このライブラリはフリー ソフトウェアです。あなたはそれを再配布および/または * GNU Lesser General Public の条件の下で修正することができます * * Free Software Foundation によって発行されたライセンス。* * ライセンスのバージョン 2.1、または (オプションで) それ以降のバージョンのいずれか。* * このライブラリは、有用であることを期待して配布されていますが、* いかなる保証もありません。* * 商品性または特定の目的への適合性に関する黙示の保証さえありません。詳細については、GNU * * Lesser General Public License を参照してください。* * GNU Lesser General Public License のコピーを * このライブラリと共に受け取っているはずです。そうでない場合は、Free Software に連絡してください * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * */
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 {
public DynamicReport buildReport() throws Exception { // Connection C = new Connection(); // C.Con(); CConnection C= new CConnection(); C.接続(); ステートメント ステートメント。結果セット rs = null; 文字列 SQL = "SELECT * FROM 学生"; stmt = C.Con().createStatement(); rs = stmt.executeQuery(SQL); 文字列 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()));
}
}
このコードを書くと次の例外が発生し、その理由が本当にわかりません
スレッド「メイン」での例外 net.sf.jasperreports.engine.JRException: Bean からフィールド値を取得中にエラーが発生しました: varchar at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123) at 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. net.sf.jasperreports.engine.fill.JRFillDataset.next(JFillDataset.java:782) で setOldValues(JRFillDataset.java:818) net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1448) でネットで net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:108) で。sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:923) で net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845) で net.sf.jasperreports.engine.fill. ar.com.fdvs.dj.test.BaseDjReportTest.testReport(BaseDjReportTest.java:93) で net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624) で JRFiller.fillReport(JRFiller.java:85) ar.com.fdvs.dj.test.Main.main(Main.java:121) で原因: java.lang.NoSuchMethodException: クラス 'class ar.com.fdvs.dj.test.domain の不明なプロパティ 'varchar' org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1322) の .Product' org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:770) の org.apache.commons.org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426) の beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:846) 111) ... 12 以上 Java 結果: 1