Jump to content
Changes to the Jaspersoft community edition download ×

Recommended Posts

By: Shiva Murali - shivva

Infinite loop

2002-05-19 20:34

Hi..

 

with jasper 0.2.5 if a field overflows then itz getting truncated. But with jasper 3 , if a field overflows, the scriptlet is entering into an infinite loop. can anyone help on this regard.

 

thanks

shivva..

 

 

By: Teodor Danciu - teodord

RE: Infinite loop

2002-05-19 23:53

 

Hi,

 

I'll try to look into this.

Maybe you could send me your XML report design

and the scriptlet class.

 

Thanks,

Teodor

 

 

 

By: Shiva Murali - shivva

RE: Infinite loop

2002-05-20 00:58

Here is my xml and the scriptlet class.

 

It gets in to infinte loop when the field "otherterms" overflows. its a blob field.

gets into infinte loop with the latest jasper (3.0).

 

 

 

888888888888888888888888888888888888888888

XML

888888888888888888888888888888888888888888

 

 

<?xml version="1.0"?>

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://www.jasperreports.com/dtds/jasperreport-0.2.5.dtd">

 

<jasperReport

name="ctrfile_print"

printOrder="Vertical"

pageWidth="595"

pageHeight="900"

leftMargin="20"

rightMargin="20"

topMargin="2"

bottomMargin="2"

isTitleNewPage="false"

isSummaryNewPage="false"

scriptletClass=" com.justcommodity.cxc.utils.ContractPrintScriptlet">

 

 

<reportFont name="Arial_Normal" isDefault="true" fontName="Arial" size="8" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<reportFont name="Arial_Bold" isDefault="false" fontName="Arial" size="8" isBold="true" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<reportFont name="Arial_Italic" isDefault="false" fontName="Arial" size="8" isItalic="true" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<reportFont name="Comic_Normal" isDefault="false" fontName="Comic Sans MS" pdfFontName="COMIC.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>

<reportFont name="Comic_Bold" isDefault="false" fontName="Comic Sans MS" isBold="true" pdfFontName="COMICBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>

<reportFont name="Courier_New" isDefault="false" fontName="Courier New Bold" isBold="true" pdfFontName="../lib/ext/courbd.ttf" pdfEncoding="Identity-H" isPdfEmbedded="true"/>

 

<parameter name="contractId" class="java.lang.String"/>

<parameter name="memberId" class="java.lang.String"/>

 

 

<queryString><![CDATA[sELECT * FROM ctr WHERE ctrid = $P{contractId} ORDER BY ctrdate]]></queryString>

<field name="ctrref" class="java.lang.String"/>

<field name="ctrdate" class="java.sql.Timestamp"/>

<field name="ctrid" class="java.lang.Integer"/>

<field name="byrid" class="java.lang.Integer"/>

<field name="slrid" class="java.lang.Integer"/>

<field name="ctrprice" class="java.lang.Double"/>

<field name="currencyid" class="java.lang.String"/>

<field name="commodityid" class="java.lang.String"/>

<field name="qtyunit" class="java.lang.String"/>

<field name="ctermid" class="java.lang.String"/>

<field name="packing" class="java.lang.String"/>

<field name="shipmonth" class="java.lang.String"/>

<field name="ctrbasisid" class="java.lang.String"/>

<field name="quantity" class="java.lang.Double"/>

<field name="paytermid" class="java.lang.Integer"/>

 

 

 

<variable name="companyname" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="companyaddr" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="companytel" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="companyfax" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="companytlx" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="commodity" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="cpaddr" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="footrfld1" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="footrfld2" class="java.lang.String" resetType="Page" calculation="System" />

<variable name="origin" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="destport" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="destportcntry" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="duringarival" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="payterms" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="otherterms" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="specdet" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="blorigin" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="unitdesc" class="java.lang.String" resetType="Page" calculation="System"/>

<variable name="specname" class="java.lang.String" resetType="Page" calculation="System"/>

 

<variable name="tempvar1" class="java.lang.String" resetType="Page" calculation="Nothing">

<variableExpression>

($P{memberId}.toString().equals($F{byrid}.toString()))?"bought from" :(($P{memberId}.toString().equals($F{slrid}.toString()))?"sold to":"***")

</variableExpression>

</variable>

 

 

<title>

<band height="70">

<textField>

<reportElement x="0" y="0" width="325" height="24" forecolor="#111111"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="20" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">$V{companyname}</textFieldExpression>

</textField>

<textField>

<reportElement x="0" y="25" width="325" height="11" forecolor="#111111"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="9" isItalic="false"/>

</textElement>

<textFieldExpression class="java.lang.String">$V{companyaddr}</textFieldExpression>

</textField>

<textField>

<reportElement x="0" y="40" width="325" height="11" forecolor="#111111"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="9" isItalic="false"/>

</textElement>

<textFieldExpression class="java.lang.String">"Tel : "+$V{companytel}+" Fax : "+$V{companyfax}+" Tlx : "+$V{companytlx}</textFieldExpression>

</textField>

<line>

<reportElement x="0" y="60" width="555" height="0" forecolor="#111111" backcolor="#EEEEEE"/>

<graphicElement stretchType="NoStretch"/>

</line>

</band>

</title>

 

<pageHeader>

<band height="0">

</band>

</pageHeader>

<columnHeader>

<band height="0">

</band>

</columnHeader>

<detail>

<band height="580">

<textField>

<reportElement x="0" y="10" width="555" height="34" forecolor="#111111"/>

<textElement textAlignment="Center" lineSpacing="Double">

<font size="15" isItalic="false"/>

</textElement>

<textFieldExpression class="java.lang.String">($P{memberId}.toString().equals($F{byrid}.toString()))?"PURCHASE CONTRACT" :(($P{memberId}.toString().equals($F{slrid}.toString()))?"SALE CONTRACT":"NONE")</textFieldExpression>

</textField>

<textField >

<reportElement x="0" y="55" width="250" height="75" forecolor="#111111"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false"/>

</textElement>

<textFieldExpression class="java.lang.String">$V{cpaddr}</textFieldExpression>

</textField>

<textField>

<reportElement x="355" y="55" width="200" height="12" forecolor="#111111"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false"/>

</textElement>

<textFieldExpression class="java.lang.String">"Contract No : " + $F{ctrref}</textFieldExpression>

</textField>

<staticText>

<reportElement x="355" y="70" width="75" height="12" forecolor="#111111"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false"/>

</textElement>

<text>Contract Date :</text>

</staticText>

<textField pattern="EEE, MMM d, yyyy">

<reportElement x="425" y="70" width="125" height="12"/>

<textElement textAlignment="Left">

<font size="10"/>

</textElement>

<textFieldExpression class="java.sql.Timestamp">

$F{ctrdate}

</textFieldExpression>

</textField>

<textField>

<reportElement x="0" y="135" width="555" height="12" />

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false"/>

</textElement>

<textFieldExpression class="java.lang.String">"We are pleased to confirm having "+$V{tempvar1}+" you under the following terms and conditions :"</textFieldExpression>

</textField>

 

<staticText>

<reportElement x="0" y="160" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<text>-- COMMODITY SPECIFICATIONS --</text>

</staticText>

<textField>

<reportElement x="10" y="178" width="545" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">$V{commodity}</textFieldExpression>

</textField>

<textField>

<reportElement x="10" y="195" width="545" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"As Per Standard "+ $V{specname}+ " specs :"

</textFieldExpression>

</textField>

<textField>

<reportElement x="10" y="212" width="545" height="100"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font reportFont="Courier_New" size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

$V{specdet}

</textFieldExpression>

</textField>

 

<textField>

<reportElement x="0" y="320" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"-- ORIGIN-- "+$V{origin}

</textFieldExpression>

</textField>

<textField>

<reportElement x="0" y="340" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"-- PRICE -- "+($F{currencyid})+" " +new DecimalFormat("0.00").format($F{ctrprice}.doubleValue())+" Per "+$V{unitdesc}+", BASIS "+$F{ctrbasisid}+" " +$V{destport}+", "+$V{destportcntry}

</textFieldExpression>

</textField>

 

<textField>

<reportElement x="0" y="360" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"-- QUANTITY -- "+ java.lang.String.valueOf(java.lang.Math.round(($F{quantity}).doubleValue()))+" "+$V{unitdesc}+", In "+$F{packing}

</textFieldExpression>

</textField>

 

 

<textField>

<reportElement x="0" y="380" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"-- SHIPMENT -- "+$V{duringarival}+" "+$F{shipmonth}

</textFieldExpression>

</textField>

 

<textField>

<reportElement x="0" y="400" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"-- PAYMENT -- "+$V{payterms}

</textFieldExpression>

</textField>

 

<textField>

<reportElement x="0" y="420" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<textFieldExpression class="java.lang.String">

"-- LOADPORT -- ANY "+$V{blorigin}+" PORT"

</textFieldExpression>

</textField>

 

<staticText>

<reportElement x="0" y="440" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true"/>

</textElement>

<text>-- OTHERS TERMS --</text>

</staticText>

 

<textField >

<reportElement x="10" y="460" width="545" height="100"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" />

</textElement>

<textFieldExpression class="java.lang.String">

$V{otherterms}

</textFieldExpression>

</textField>

 

 

</band>

</detail>

<columnFooter>

<band height="0">

</band>

</columnFooter>

 

<pageFooter>

<band height="0">

</band>

</pageFooter>

 

<summary>

<band height="150">

<staticText>

<reportElement x="0" y="0" width="555" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false"/>

</textElement>

<text>Please stamp , sign and return to us the duplicate copy. </text>

</staticText>

<textField>

<reportElement x="0" y="40" width="225" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" />

</textElement>

<textFieldExpression class="java.lang.String">$V{companyname}</textFieldExpression>

</textField>

<staticText>

<reportElement x="330" y="40" width="225" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" />

</textElement>

<text>CONFIRMED ACCEPTANCE</text>

</staticText>

<staticText>

<reportElement x="0" y="110" width="225" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true" />

</textElement>

<text>.....................................................</text>

</staticText>

<staticText>

<reportElement x="330" y="110" width="225" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" isBold="true" />

</textElement>

<text>.....................................................</text>

</staticText>

<textField>

<reportElement x="0" y="130" width="225" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" />

</textElement>

<textFieldExpression class="java.lang.String">$V{footrfld1}</textFieldExpression>

</textField>

<textField>

<reportElement x="330" y="130" width="225" height="12"/>

<textElement textAlignment="Left" lineSpacing="Single">

<font size="10" isItalic="false" />

</textElement>

<textFieldExpression class="java.lang.String">$V{footrfld2}</textFieldExpression>

</textField>

 

</band>

</summary>

</jasperReport>

 

 

 

888888888888888888888888888888888888888888

SCRIPTLET

888888888888888888888888888888888888888888

package com.justcommodity.cxc.utils;

 

/**

* Title:

* Description:

* Copyright: Copyright © 2000 Oilgrains Venture Asia Pacific Pte Ltd

* Company: Oilgrains Venture Asia Pacific Pte Ltd

* @author S.Murali

* @version 1.0

*/

 

 

 

import dori.jasper.engine.*;

import java.sql.*;

import java.util.*;

import java.math.BigDecimal;

import javax.naming.InitialContext;

import javax.sql.DataSource;

import java.util.*;

import javax.rmi.PortableRemoteObject;

import java.text.DecimalFormat;

 

 

/**

*

*/

public class ContractPrintScriptlet extends JRDefaultScriptlet {

 

private String ctrid = new String();

private String mbrid = new String();

private String company = new String();

private Connection con = null;

 

 

/**

*

*/

public void beforeReportInit() throws JRScriptletException

{

System.out.println("BeforeReportInit***");

this.ctrid = (String)this.getParameterValue("contractId");

this.mbrid = (String)this.getParameterValue("memberId");

this.con = openConnection();

System.out.println("Connection initialized...........");

 

 

}

 

 

/**

*

*/

public void afterReportInit() throws JRScriptletException

{

System.out.println("AfterReportInit***");

 

 

}

 

 

/**

*

*/

public void beforePageInit() throws JRScriptletException

{

System.out.println("BeforePageInit***" );

 

 

}

 

 

/**

*

*/

public void afterPageInit() throws JRScriptletException

{

System.out.println("AfterPageInit***" );

setVariables();

}

 

 

/**

*

*/

public void beforeColumnInit() throws JRScriptletException

{

System.out.println("BeforeColumnInit***");

}

 

 

/**

*

*/

public void afterColumnInit() throws JRScriptletException

{

System.out.println("AfterColumnInit***");

}

 

 

/**

*

*/

public void beforeGroupInit(String groupName) throws JRScriptletException

{

System.out.println("BeforeGroupInit***" );

}

 

 

/**

*

*/

public void afterGroupInit(String groupName) throws JRScriptletException

{

System.out.println("AfterGroupInit***");

 

}

 

 

/**

*

*/

public void beforeDetailEval() throws JRScriptletException

{

System.out.println("BeforeDetail***");

 

}

 

 

/**

*

*/

public void afterDetailEval() throws JRScriptletException

{

System.out.println("AfterDetail***");

 

closeConnection();

 

}

 

private static Connection openConnection() {

try {

/* String driver ="org.firebirdsql.jdbc.FBDriver";

String connectString = "jdbc:firebirdsql:knuth/3050:/home/firebird/cxcdata-v10.gdb";

String user = "sysdba";//"sa";

String password = "masterkey";//"";

 

 

Class.forName(driver);

Connection conn = DriverManager.getConnection(connectString, user, password);

return conn; */

 

DataSource ds = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/cxcdata");

return ds.getConnection();

}catch(Exception ex) {

ex.printStackTrace();

return null;

}

}

 

private void closeConnection() {

try {

this.con.close();

this.con = null;

System.out.println("Connection closed.......");

} catch (Exception ex) {

ex.printStackTrace();

}

}

 

private void setVariables() {

try {

String sql1 = "Select mbrname,mbraddress from jcmbr where mbrid = "+this.mbrid;

String sql2 = "Select contactnum from jcmbrcontact where contacttypeid='P' and mbrid = "+this.mbrid;

String sql3 = "Select contactnum from jcmbrcontact where contacttypeid='F' and mbrid = "+this.mbrid;

String sql4 = "Select contactnum from jcmbrcontact where contacttypeid='T' and mbrid = "+this.mbrid;

 

ResultSet rs = null;

 

 

System.out.println(sql1);

 

if (con == null)

this.con = openConnection();

 

rs = con.createStatement().executeQuery(sql1);

if (rs == null || !rs.next()){

this.setVariableValue("companyname","*");

this.setVariableValue("companyaddr","*");

}else{

this.setVariableValue("companyname",rs.getString("mbrname"));

this.setVariableValue("companyaddr",formatAddress(rs.getString("mbraddress").trim(),"n"));

rs.close();

}

 

System.out.println(sql2);

rs = con.createStatement().executeQuery(sql2);

if (rs == null || !rs.next()){

this.setVariableValue("companytel","*");

}else{

this.setVariableValue("companytel",rs.getString("contactnum"));

rs.close();

}

 

System.out.println(sql3);

rs = con.createStatement().executeQuery(sql3);

if (rs == null || !rs.next()){

this.setVariableValue("companyfax","*");

}else{

this.setVariableValue("companyfax",rs.getString("contactnum"));

rs.close();

}

 

System.out.println(sql4);

rs = con.createStatement().executeQuery(sql4);

if (rs == null || !rs.next()){

this.setVariableValue("companytlx","*");

}else{

this.setVariableValue("companytlx",rs.getString("contactnum"));

rs.close();

}

this.company = this.getVariableValue("companyname").toString();

 

 

if(this.getParameterValue("memberId").toString().trim().equals(this.getFieldValue("slrid").toString().trim())){

this.setVariableValue("footrfld1","SELLER");

this.setVariableValue("footrfld2","BUYER");

}else if(this.getParameterValue("memberId").toString().trim().equals(this.getFieldValue("byrid").toString().trim())){

this.setVariableValue("footrfld1","BUYER");

this.setVariableValue("footrfld2","SELLER");

}

 

this.setVariableValue("companyname",this.company);

 

System.out.println("Seller id:"+this.getFieldValue("slrid"));

if (this.mbrid.equals(this.getFieldValue("slrid").toString().trim()))

this.setVariableValue("cpaddr",getAddress(this.getFieldValue("byrid").toString()));

else

this.setVariableValue("cpaddr",getAddress(this.getFieldValue("slrid").toString()));

 

 

String sql = "Select commodityname from jccommodity where commodityid = '"+ this.getFieldValue("commodityid")+"'";

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("commodity","NONE");

}else{

this.setVariableValue("commodity",rs.getString("COMMODITYNAME"));

rs.close();

}

 

this.setVariableValue("specdet",getSpecDet());

 

sql = "select jccountry.countryname from "+

" ctrorigin,jccountry where ctrorigin.countryid = jccountry.countryid "+

" and ctrorigin.ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("origin","NONE");

}else{

this.setVariableValue("origin",rs.getString("COUNTRYNAME"));

rs.close();

}

 

 

sql = "Select commodityname from jccommodity where commodityid = '"+ this.getFieldValue("commodityid")+"'";

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("commodity","NONE");

}else{

this.setVariableValue("commodity",rs.getString("COMMODITYNAME"));

rs.close();

}

 

sql ="select portname,countryname from ctrcfmdport,jcport,jccountry "+

"where ctrcfmdport.portid = jcport.portid and jcport.countryid = jccountry.countryid "+

" and ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("destport","NONE");

this.setVariableValue("destportcntry","NONE");

}else{

this.setVariableValue("destport",rs.getString("PORTNAME"));

this.setVariableValue("destportcntry",rs.getString("COUNTRYNAME"));

rs.close();

}

 

 

sql ="select isduring from ctrcnfstatus "+

"where ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("duringarival","NONE");

}else{

this.setVariableValue("duringarival",new String(rs.getBoolean("ISDURING")== true ?"DURING":"ARRIVAL"));

rs.close();

}

 

 

sql ="select portname,countryname from ctrcfmdport,jcport,jccountry "+

"where ctrcfmdport.portid = jcport.portid and jcport.countryid = jccountry.countryid "+

" and ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("destport","NONE");

this.setVariableValue("destportcntry","NONE");

}else{

this.setVariableValue("destport",rs.getString("PORTNAME"));

this.setVariableValue("destportcntry",rs.getString("COUNTRYNAME"));

rs.close();

}

 

sql ="select paymethoddescn from jcpayterms a,jcpaymentmethod b "+

" where a.paytype = b.paymethodid and paytermid = "+this.getFieldValue("paytermid");

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("payterms","NONE");

}else{

this.setVariableValue("payterms",rs.getString("PAYMETHODDESCN"));

rs.close();

}

 

sql ="Select maindesc from jccnfterms a,ctrcnfterms b where a.cnftermid = b.cnftermid and b.ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("otherterms","NONE");

}else{

String descn = rs.getString("MAINDESC");

this.setVariableValue("otherterms",(descn == null ? "-NULL-":descn));

rs.close();

}

 

sql ="select countryname from ctrcnfstatus a,jccountry b "+

" where a.blorigin = b.countryid and a.ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("blorigin","NONE");

}else{

this.setVariableValue("blorigin",rs.getString("COUNTRYNAME"));

rs.close();

}

 

sql ="select qtydescn from jcqtyunit "+

" where qtyunitid = '"+this.getFieldValue("qtyunit")+"'";

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("unitdesc","NONE");

}else{

this.setVariableValue("unitdesc",rs.getString("QTYDESCN"));

rs.close();

}

 

 

 

sql ="select specname from jccommodityspec a,ctrcfmspec b"+

" where a.specid = b.specid and specseqid = 0 and b.ctrid = "+this.ctrid;

System.out.println(sql);

rs = con.createStatement().executeQuery(sql);

if (rs == null || !rs.next()){

this.setVariableValue("specname","NONE");

}else{

this.setVariableValue("specname",rs.getString("SPECNAME"));

rs.close();

}

 

 

} catch (Exception ex) {

ex.printStackTrace();

}

}

 

private String getAddress(String cpmbrid) {

try {

ResultSet rs = null;

String sql = "Select mbrname,mbraddress from jcmbr where mbrid = "+cpmbrid;

System.out.println(sql);

String addr = new String();

 

if (con == null)

con = openConnection();

 

rs = con.createStatement().executeQuery(sql);

 

if (rs == null || !rs.next()){

return "NONE";

}else{

addr = rs.getString("MBRNAME");

addr = addr + "n" + rs.getString("MBRADDRESS");

rs.close();

}

 

System.out.println("Address:n"+addr);

return addr.trim();

 

} catch (Exception ex) {

ex.printStackTrace();

return null;

}

}

 

private String getSpecDet() {

try {

String sql = "select d.specid,d.specname, specmin, specmax,specunit from"+

" jcspecdetails d, jccommodityspec m,ctrcfmspec r where" +

" r.ctrid = "+this.ctrid +" and r.specid = m.specid and m.specid = d.specid ";

 

System.out.println(sql);

StringBuffer spec = new StringBuffer("");

 

if (con == null)

con = openConnection();

 

ResultSet rs = con.createStatement().executeQuery(sql);

 

if (rs == null || !rs.next())

return "NONE";

 

do {

BigDecimal min = rs.getBigDecimal("SPECMIN");

BigDecimal max = rs.getBigDecimal("SPECMAX");

String unit = rs.getString("SPECUNIT");

String name = padBlanks(rs.getString("SPECNAME"),20,'B');

System.out.println(name);

 

if (unit == null )

unit = "-nill-";

else if (unit.trim().equals("%"))

unit = "PCT";

 

DecimalFormat fmt = (DecimalFormat)java.text.NumberFormat.getInstance();

fmt.setDecimalSeparatorAlwaysShown(true);

fmt.applyPattern("0.00");

 

if (min != null){

spec.append(name).append(padBlanks(fmt.format(min.doubleValue()),8,'F')).append(" ").append(padBlanks(unit,10,'B')).append(" ").append(" MIN");

System.out.println(spec.toString());

}

if (max != null) {

max = new BigDecimal(java.lang.Math.round(max.doubleValue()));

spec.append("n").append(name).append(padBlanks(fmt.format(max.doubleValue()),8,'F')).append(" ").append(padBlanks(unit,10,'B')).append(" ").append(" MAX").append("n");

System.out.println(spec.toString());

}

 

}while(rs.next());

 

 

rs.close();

return spec.toString();

 

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

 

private String padBlanks(String str,int size,char flag) {

if (str == null)

str = new String("-nill-");

else

str = str.trim();

 

System.out.println(str.length());

int len = str.length();

if (flag == 'B') {

for(int i=0;i<=size- len;i++)

str = str + " ";

}else if (flag =='F') {

String tmp = new String();

for(int i=0;i<=size- len;i++)

tmp = tmp + " ";

str = tmp+str;

}

 

return str;

}

 

private String formatAddress(String srcAddr,String delim) {

try {

StringTokenizer tokens = new StringTokenizer(srcAddr,delim);

String dstAddr = new String();

while(tokens.hasMoreTokens())

dstAddr = dstAddr+ " "+tokens.nextToken().trim();

 

return dstAddr;

} catch (Exception ex) {

ex.printStackTrace();

return null;

}

}

 

}

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...