将数字转换为本地(UTF8)JasperReports中的孟加拉语数字& MySQL的 [英] Converting Numbers to Local (UTF8) Bengali numbers in JasperReports & MySQL

查看:137
本文介绍了将数字转换为本地(UTF8)JasperReports中的孟加拉语数字& MySQL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在填写报告之前将英文数字转换为孟加拉语。我从MySQL获得的数据:

I am trying to convert the English numbers to Bengali numbers before filling the report. The data i am getting from MySQL:

SELECT brand.id,brand.brand,model.model FROM brand INNER JOIN model ON brand.id=model.id AND model.id=$P{ID}

例如if model .model列返回一个数字322然后它应该首先将数字转换为孟加拉语版本(3২২)然后它将填充报告。这样的事情:

For example if model.model columns return a number 322 then it should first convert the number to Bengali version(৩২২) and then it will fill the report.Something like this:

一个|两个|三个
1 | ২| 3

One | two | Three ১ | ২ | ৩

这是孟加拉语中的0-9:

Here is the 0-9 in Bengali:

0 1২3 4 5 6 7 8 9

০ ১ ২ ৩ ৪ ৫ ৬ ৭ ৮ ৯

我在考虑如下替换方法:

I was thinking about replace method as follows:

char[] en ={'0','1','2','3','4','5','6','7','8','9'};
char[] bn ={'০','১','২','৩','৪','৫','৬','৭','৮','৯'};
en.replace(bn)

也许它不起作用!

我不知道从哪里开始!但这是我目前的申请代码:

I am just not sure where to start ! But here is my current Application Codes:

Java代码:

@FXML
public TextField one;

public void click(ActionEvent event) throws JRException, SQLException, ClassNotFoundException, IllegalAccessException, UnsupportedLookAndFeelException, InstantiationException {
    String reportSrcFile = "/home/sample/learn.jrxml";

    JasperReport jasperReport1 = JasperCompileManager.compileReport(reportSrcFile);

    Connection conn = SqliConnect.getMySQLConnection();
    int two = Integer.parseInt(one.getText());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ID",one.getText());

    JasperPrint print = JasperFillManager.fillReport(jasperReport1,
            parameters, conn);

    JasperViewer jv = new JasperViewer(print);
    jv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jv.setTitle("Test Report");

    jv.setVisible(true);
}

报告模板:

<subDataset name="Dataset1" uuid="2691431f-5c6f-403f-94cc-829c17ef1636">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Learn"/>
    <parameter name="ID" class="java.lang.Integer">
        <parameterDescription><![CDATA[Get ID]]></parameterDescription>
        <defaultValueExpression><![CDATA[$P{ID}]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT brand.id,brand.brand,model.model FROM brand INNER JOIN model ON brand.id=model.id WHERE model.id=$P{ID}]]>
    </queryString>
    <field name="id" class="java.lang.Integer"/>
    <field name="brand" class="java.lang.String"/>
    <field name="model" class="java.lang.String"/>
</subDataset>
<parameter name="ID" class="java.lang.Integer" isForPrompting="false">
    <parameterDescription><![CDATA[]]></parameterDescription>
    <defaultValueExpression><![CDATA[$P{ID}]]></defaultValueExpression>
</parameter>
<queryString>
    <![CDATA[SELECT brand.id,brand.brand,model.model FROM brand INNER JOIN model ON brand.id=model.id WHERE model.id=$P{ID}]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<field name="brand" class="java.lang.String"/>
<field name="model" class="java.lang.String"/>
<title>
    <band height="79" splitType="Stretch">
        <textField>
            <reportElement x="11" y="16" width="100" height="30" uuid="d1485589-a4cf-4ab9-b896-0ef480beced4"/>
            <textFieldExpression><![CDATA[$P{ID}]]></textFieldExpression>
        </textField>
    </band>
</title>
<detail>
    <band height="250" splitType="Stretch">
        <componentElement>
            <reportElement x="0" y="0" width="555" height="250" uuid="e199bd58-8408-4711-85d5-ba76db9691b7">
                <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                <property name="com.jaspersoft.studio.components.autoresize.proportional" value="true"/>
            </reportElement>
            <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                <datasetRun subDataset="Dataset1" uuid="fbb4dafa-4284-4118-9d2b-46d88c63a31b">
                    <datasetParameter name="ID">
                        <datasetParameterExpression><![CDATA[$P{ID}]]></datasetParameterExpression>
                    </datasetParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                </datasetRun>
                <jr:column width="185" uuid="9a6b765f-b6d4-4753-909e-dd091b296654">
                    <jr:columnHeader style="Table_CH" height="30">
                        <staticText>
                            <reportElement x="0" y="0" width="185" height="30" uuid="7e644d1c-a893-49df-a18a-bf788eb6b92a"/>
                            <text><![CDATA[id]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:columnFooter style="Table_CH" height="30"/>
                    <jr:detailCell style="Table_TD" height="30">
                        <textField>
                            <reportElement x="0" y="0" width="185" height="30" uuid="848a53bf-2b2e-46df-a7aa-26fc0b897c85"/>
                            <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="185" uuid="514580a5-f09c-43d1-952e-d4769c2e4686">
                    <jr:columnHeader style="Table_CH" height="30">
                        <staticText>
                            <reportElement x="0" y="0" width="185" height="30" uuid="c01152e9-1547-472b-946e-92011c02bc94"/>
                            <text><![CDATA[brand]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:columnFooter style="Table_CH" height="30"/>
                    <jr:detailCell style="Table_TD" height="30">
                        <textField>
                            <reportElement x="0" y="0" width="185" height="30" uuid="98c84ae5-b289-459a-b34b-a9becf43b9ce"/>
                            <textFieldExpression><![CDATA[$F{brand}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="185" uuid="5c1d2026-45bc-4ec8-8be4-c444e47d093d">
                    <jr:columnHeader style="Table_CH" height="30">
                        <staticText>
                            <reportElement x="0" y="0" width="185" height="30" uuid="81f76de4-a68b-41c3-a2e8-bbaa625b71be"/>
                            <text><![CDATA[model]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:columnFooter style="Table_CH" height="30"/>
                    <jr:detailCell style="Table_TD" height="30">
                        <textField>
                            <reportElement x="0" y="0" width="185" height="30" uuid="d69c690e-05a4-453a-93ea-9061523975ad"/>
                            <textFieldExpression><![CDATA[$F{model}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</detail>

这样做的正确方法是什么?

What is the Right way to do it?

推荐答案

您还可以在Java代码中创建替换字符串并在参数映射中使用它:

You also could create a replacement String in the Java code and use it in the parameters map:

   String replacedOne = one.getText().replaceAll("0","০").replaceAll("1","১").replaceAll("2","২").replaceAll("3","৩").replaceAll("4","৪").replaceAll("5","৫").replaceAll("6","৬").replaceAll("7","৭").replaceAll("8","৮").replaceAll("9","৯");
   parameters.put("replacedID",replacedOne);

或者更好,你可以直接在你的jrxml文件中执行替换,而不需要修改java文件,使用此(非常长)表达式而不是$ F {model}:

Or better, you can perform the replacement directly in your jrxml file, with no need to modify the java file, by using this (very long) expression instead of $F{model}:

$F{model}.replaceAll("0","০").replaceAll("1","১").replaceAll("2","২").replaceAll("3","৩").replaceAll("4","৪").replaceAll("5","৫").replaceAll("6","৬").replaceAll("7","৭").replaceAll("8","৮").replaceAll("9","৯");

这篇关于将数字转换为本地(UTF8)JasperReports中的孟加拉语数字&amp; MySQL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆