I created a hibernate program and wrote a query and got the following error:
I got an exception stating java.lang.ClassCastException: java.lang.Double
String qry="Select Distinct (s2Taxper) from S2 where s2Tc='601' AND s2Txcd!=''";
Iterator atItr2=hbSession.createQuery(qry).iterate();
String qry1="Select ahCode,ahName,ahRcNumber,ahCentralSalesTaxNumber From AccountHeader ORDER BY ahName ASC";
Iterator atItr1=hbSession.createQuery(qry1).iterate();
mainBean=new VatMainBean();
VatSubBeanList=new ArrayList<VatSubBean>();
while(atItr1.hasNext()){
subBean=new VatSubBean();
Object[] obj1=(Object[])atItr1.next();
String ahCode =(String)obj1[0];
String ahName =(String)obj1[1];
String ahRcNumber=(String)obj1[2];
String ahCentralSalesTaxNumber=(String)obj1[3];
if("v".equalsIgnoreCase(type)){
if(ahRcNumber!=null&&!"".equalsIgnoreCase(ahRcNumber)){
if(ahRcNumber.indexOf("/")<0&&ahRcNumber.indexOf(":")<0&&ahRcNumber.indexOf(" ")<0){
//buyersTinNo.trim();
if(ahRcNumber.length()==11){
buyersTinNo=ahRcNumber;
}
}
}
}
else{
if(ahCentralSalesTaxNumber!=null&&!"".equalsIgnoreCase(ahCentralSalesTaxNumber)){
buyersTinNo=ahCentralSalesTaxNumber;
}
}
DoubleCheck doubleObj1=new DoubleCheck();
List<String> taxPerList=new ArrayList<String>();
int i = 0;
while (atItr2.hasNext()){
Object[] obj2=(Object[])atItr2.next();// error is shown here
String s2Taxper=(String)obj2[0];
int s1Docno=(Integer)obj2[1];
if(Double.parseDouble(s2Taxper)>0){
taxPerList.add(s2Taxper);
}
How do I rectify this ?
One of you fileds is double and you try to cast it to string.
Look on the coulmn defintion.
If you want to convert double to string you should do this by Double.tostring