The Artima Developer Community
Sponsored Link

Java Answers Forum
Record In Jsp & back end differ for same query

7 replies on 1 page. Most recent reply: Nov 9, 2003 8:37 PM by Birendar S Waldiya

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Record In Jsp & back end differ for same query Posted: Nov 5, 2003 9:19 PM
Reply to this message Reply
Advertisement
Hi,
I have a strange problem. Im executing a database query that returns 1 record in jsp( using ResultSet.next()) where as when i execute same query in backend i get two recods .can anyone tell me why??
thaks
rgds
Birendar S Waldiya


the jsp code that process the query is :-
<code>

while(fetchRS.next())
{

if(subTotalReq && !firstLoop && !tempValue.equals(fetchRS.getString(1))){
tempParam = " and " + Columns.get(0).toString() + "$'" + tempValue+"'";
tempHeader = Headings.get(0).toString() + ":" + tempValue;

out.println("<tr>");
out.println("<td class=\"TrtblS_la\" style=\"background-color:silver\" colspan=\"2\"><b>SUB Total For "+tempValue+"</b></td>");
out.println("<td class=\"TrtblC_ra\" style=\"background-color:silver\" colspan=\""+(columnsCount-2)+"\"><a class=\"DLnk\" href=\""+calledPage+"?parameters="+tempParam.replace('&','^').replace('+',' |').replace('%','~')+"&headers="+tempHeader.replace('&','^').replace('+' ,'|')+"&condition="+condition.toString().replace('%','~').replace('&','^ ').replace('+','|')+"&searchBy="+searchBy+"&exp_from_date="+exp_from_dat e+"&exp_to_date="+exp_to_date+"&from_month="+from_month+"&to_month=" +to_month+"\"><strong>"+formatter.format(subTotal)+"</strong>< /a></td>");

out.println("</tr>");
pageContent.append("\n");
pageContent.append("Sub Total For "+tempValue+"\t"+tabs+formatter.format(subTotal));
subTotal = 0;
}




pageContent.append("\n");
parameters = new StringBuffer();
headers = new StringBuffer();


out.println("<tr>");
for(int j =0; j< columnsCount; j++)
{
if( j == columnsCount-1){
out.println("<td class=\"TrtblC_ra\" colspan=\"1\"><a class=\"DLnk\" href=\""+calledPage+"?parameters="+(parameters.toString()).replace('&','^') .replace('+','|').replace('%','~').replace('"','*')+"&headers="+headers.toSt ring().replace('&','^').replace('+','|')+"&condition="+condition.toStrin g().replace('%','~').replace('&','^').replace('+','|')+"&searchBy="+sear chBy+"&exp_from_date="+exp_from_date+"&exp_to_date="+exp_to_date+"&f rom_month="+from_month+"&to_month="+to_month+"\">"+formatter.format(fetch RS.getDouble(j+1))+"</a></td>");
totalINR = totalINR + fetchRS.getDouble(j+1);
subTotal = subTotal + fetchRS.getDouble(j+1);
pageContent.append(formatter.format(fetchRS.getDouble(j+1))+"\t");
}else{
out.println("<td class=\"TrtblS_la\" colspan=\"1\">"+fetchRS.getString(j+1)+"</td>");
pageContent.append(fetchRS.getString(j+1)+"\t");
if((Columns.get(j).toString()).equals("PROJ_DESCRIPTION")){
parameters.append(" and "+Columns.get(j)+" like'"+fetchRS.getString(j+1).replace('"','*')+"%'");
}else{
if((Columns.get(j).toString()).equalsIgnoreCase("CUSTOMER_NAME")){
parameters.append(" and customer_id $'"+fetchRS.getString("customer_id")+"'");
}else{
parameters.append(" and "+Columns.get(j)+"$'"+fetchRS.getString(j+1)+"'");
}

}//end if
headers.append(" "+Headings.get(j)+"$"+fetchRS.getString(j+1)+(j%2==0?"<BR>":"&nbsp;") );
}//End of IF
}// End of For
out.println("</tr>");
recCount++;
tempValue = fetchRS.getString(1);
firstLoop = false;
}//END OF WHILE

</code>


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Record In Jsp & back end differ for same query Posted: Nov 6, 2003 2:39 AM
Reply to this message Reply
int i = 0;
while(fetchRS.next())
{
i++;
}
out.println("Number of records are : " + i);

I assume fetchRS is your result set. Why don't you embed this code in your servlet and run and see as to what number the variable i is generating.

Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Re: Record In Jsp & back end differ for same query Posted: Nov 6, 2003 3:18 AM
Reply to this message Reply
>
> int i = 0;
> while(fetchRS.next())
> {
> i++;
> }
> out.println("Number of records are : " + i);
> 

> I assume fetchRS is your result set. Why don't you embed
> this code in your servlet and run and see as to what
> number the variable i is generating.

Surely I did that before posting this problem, i get the 0 where it is expected to be 0,1..
I tried to fetch only the count not record but to my surprise it didnt gave me the correct result.
Let me see once more ..

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Record In Jsp & back end differ for same query Posted: Nov 6, 2003 4:24 AM
Reply to this message Reply
Then to investigate more you should post the where you are actually executing the query and getting the result set.

Also use the [ java] [ /java] tags to poste the code and not the <code> tag. (Ignore the space inside the tag)

Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Re: Record In Jsp & back end differ for same query Posted: Nov 6, 2003 5:58 AM
Reply to this message Reply
<pre>Here is the code that is created upon the option i give to get the current page & i have made sure that the query that is printed is just the query which is executed at the back end by putting out.println(querey): just before it is executed The query I get is :--
</pre>


<pre><I>select swon_category, sum(nvl(amount_inr,0)) amount_inr from ((select * from tcs_mis_operational_cost_sec_v where swon_category in ('Branch','Branch - Support','Corporate','Corporate Function','Delivery Centre' ,'Leave','Offshore Delivery Centre','Training','Training - CEP','Training - ITP','Training - MDP','Unallocated') and (dc_emp_no = '42021' or ip_emp_no = '42021' or sp_emp_no = '42021' or sect_emp_no = '42021' or lc_emp_no = '42021' or sub_ip_emp_no = '42021' or sub_sp_emp_no = '42021' ) ) union (select a.* from tcs_mis_operational_cost_sec_v a where swon_category in ('Branch','Branch - Support','Corporate','Corporate Function','Delivery Centre' ,'Leave','Offshore Delivery Centre','Training','Training - CEP','Training - ITP','Training - MDP','Unallocated') and exists (select 1 from tcs_mis_project_key_members_t b where (b.owner_emp_number='42021' or b.gl_emp_number='42021' or b.am_emp_number='42021' or b.rm_emp_number='42021' or b.brm_emp_number='42021' or b.deputy_owner_emp_number='42021' or b.supervisor_emp_number='42021' or b.bdm_emp_number='42021' or b.key_member_emp_number='42021' ) and a.project_number = b.project_number ) )) where 1=1 and UPPER(swon_category) like UPPER('%') and exp_date between to_date('03/01/2003','mm/dd/yyyy') and to_date('03/31/2003','mm/dd/yyyy') group by swon_category order by swon_category
</i></pre>


<b>the code is :-</b>
<java>
try{
out.println("The Query==>"+selectQuery +"<br>"); //<I><B>THIS IS THE QUERY THAT IS GIVEN ABOVE </B></I>
fetchRS = sttt.executeQuery(selectQuery.toString());
int k =0 ;
while(fetchRS.next()) {
out.println(k);
k++;
if(subTotalReq && !firstLoop && !tempValue.equals(fetchRS.getString(1))){
tempParam = " and " + Columns.get(0).toString() + "$'" + tempValue+"'";
tempHeader = Headings.get(0).toString() + ":" + tempValue;
out.println("<tr>");
out.println("<td class=\"TrtblS_la\" style=\"background-color:silver\" colspan=\"2\"><b>SUB Total For "+tempValue+"</b></td>");
out.println("<td class=\"TrtblC_ra\" style=\"background-color:silver\" colspan=\""+(columnsCount-2)+"\"><a class=\"DLnk\" href=\""+calledPage+"?parameters="+tempParam.replace('&','^').replace('+',' |').replace('%','~')+"&headers="+tempHeader.replace('&','^').replace('+' ,'|')+"&condition="+condition.toString().replace('%','~').replace('&','^ ').replace('+','|')+"&searchBy="+searchBy+"&exp_from_date="+exp_from_dat e+"&exp_to_date="+exp_to_date+"&from_month="+from_month+"&to_month=" +to_month+"\"><strong>"+formatter.format(subTotal)+"</strong>< /a></td>");
out.println("</tr>");
subTotal = 0;
}
parameters = new StringBuffer();
headers = new StringBuffer();
out.println("<tr>");
for(int j =0; j< columnsCount; j++)
{
if( j == columnsCount-1){
out.println("<td class=\"TrtblC_ra\" colspan=\"1\"><a class=\"DLnk\" href=\""+calledPage+"?parameters="+(parameters.toString()).replace('&','^') .replace('+','|').replace('%','~').replace('"','*')+"&headers="+headers.toSt ring().replace('&','^').replace('+','|')+"&condition="+condition.toStrin g().replace('%','~').replace('&','^').replace('+','|')+"&searchBy="+sear chBy+"&exp_from_date="+exp_from_date+"&exp_to_date="+exp_to_date+"&f rom_month="+from_month+"&to_month="+to_month+"\">"+formatter.format(fetch RS.getDouble(j+1))+"</a></td>");
totalINR = totalINR + fetchRS.getDouble(j+1);
subTotal = subTotal + fetchRS.getDouble(j+1);

}else{
out.println("<td class=\"TrtblS_la\" colspan=\"1\">"+fetchRS.getString(j+1)+"</td>");

if((Columns.get(j).toString()).equals("PROJ_DESCRIPTION")){
parameters.append(" and "+Columns.get(j)+" like'"+fetchRS.getString(j+1).replace('"','*')+"%'");
}else{
if((Columns.get(j).toString()).equalsIgnoreCase("CUSTOMER_NAME")){
parameters.append(" and customer_id $'"+fetchRS.getString("customer_id")+"'");
}else{
parameters.append(" and "+Columns.get(j)+"$'"+fetchRS.getString(j+1)+"'");
}

}//end if
headers.append(" "+Headings.get(j)+"$"+fetchRS.getString(j+1)+(j%2==0?"<BR>":" "));
}//End of IF
}// End of For
out.println("</tr>");
recCount++;
tempValue = fetchRS.getString(1);
firstLoop = false;
}//END OF WHILE
}catch(Exception exp){
</java>

Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Re: Record In Jsp & back end differ for same query Posted: Nov 6, 2003 6:05 AM
Reply to this message Reply
Here is the code that is created upon the option i give to get the current page & i have made sure that the query that is printed is just the query which is executed at the back end by putting out.println(querey): just before it is executed The query I get is :--
select swon_category, sum(nvl(amount_inr,0)) amount_inr from ((select * from tcs_mis_operational_cost_sec_v where swon_category in ('Branch','Branch - Support','Corporate','Corporate Function','Delivery Centre' ,'Leave','Offshore Delivery Centre','Training','Training - CEP','Training - ITP','Training - MDP','Unallocated') and (dc_emp_no = '42021' or ip_emp_no = '42021' or sp_emp_no = '42021' or sect_emp_no = '42021' or lc_emp_no = '42021' or sub_ip_emp_no = '42021' or sub_sp_emp_no = '42021' ) ) union (select a.* from tcs_mis_operational_cost_sec_v a where swon_category in ('Branch','Branch - Support','Corporate','Corporate Function','Delivery Centre' ,'Leave','Offshore Delivery Centre','Training','Training - CEP','Training - ITP','Training - MDP','Unallocated') and exists (select 1 from tcs_mis_project_key_members_t b where (b.owner_emp_number='42021' or b.gl_emp_number='42021' or b.am_emp_number='42021' or b.rm_emp_number='42021' or b.brm_emp_number='42021' or b.deputy_owner_emp_number='42021' or b.supervisor_emp_number='42021' or b.bdm_emp_number='42021' or b.key_member_emp_number='42021' ) and a.project_number = b.project_number ) )) where 1=1 and UPPER(swon_category) like UPPER('%') and exp_date between to_date('03/01/2003','mm/dd/yyyy') and to_date('03/31/2003','mm/dd/yyyy') group by swon_category order by swon_category


the code is :-
try{
out.println("The Query==>"+selectQuery +"<br>"); //THIS IS THE QUERY THAT IS GIVEN ABOVE 
fetchRS = sttt.executeQuery(selectQuery.toString());
int k =0 ;
while(fetchRS.next()) {
out.println(k);
k++;
if(subTotalReq && !firstLoop && !tempValue.equals(fetchRS.getString(1))){
tempParam = " and " + Columns.get(0).toString() + "$'" + tempValue+"'";
tempHeader = Headings.get(0).toString() + ":" + tempValue;
out.println("<tr>");
out.println("<td class=\"TrtblS_la\" style=\"background-color:silver\" colspan=\"2\"><b>SUB Total For "+tempValue+"</b></td>");
out.println("<td class=\"TrtblC_ra\" style=\"background-color:silver\" colspan=\""+(columnsCount-2)+"\"><a class=\"DLnk\" href=\""+calledPage+"?parameters="+tempParam.replace('&','^').replace('+','|'). replace('%','~')+"&headers="+tempHeader.replace('&','^').replace('+','|')+"&cond ition="+condition.toString().replace('%','~').replace('&','^').replace('+','|')+ "&searchBy="+searchBy+"&exp_from_date="+exp_from_date+"&exp_to_date="+exp_to_dat e+"&from_month="+from_month+"&to_month="+to_month+"\"><strong>"+formatt er.format(subTotal)+"</strong></a></td>");
out.println("</tr>");
subTotal = 0;
}
parameters = new StringBuffer();
headers = new StringBuffer();
out.println("<tr>");
for(int j =0; j< columnsCount; j++)
{
if( j == columnsCount-1){
out.println("<td class=\"TrtblC_ra\" colspan=\"1\"><a class=\"DLnk\" href=\""+calledPage+"?parameters="+(parameters.toString()).replace('&','^').rep lace('+','|').replace('%','~').replace('"','*')+"&headers="+headers.toString().r eplace('&','^').replace('+','|')+"&condition="+condition.toString().replace('%', '~').replace('&','^').replace('+','|')+"&searchBy="+searchBy+"&exp_from_date="+e xp_from_date+"&exp_to_date="+exp_to_date+"&from_month="+from_month+"&to_month="+ to_month+"\">"+formatter.format(fetchRS.getDouble(j+1))+"</a></td> ;");
totalINR = totalINR + fetchRS.getDouble(j+1);
subTotal = subTotal + fetchRS.getDouble(j+1);
 
}else{
out.println("<td class=\"TrtblS_la\" colspan=\"1\">"+fetchRS.getString(j+1)+"</td>");
 
if((Columns.get(j).toString()).equals("PROJ_DESCRIPTION")){
parameters.append(" and "+Columns.get(j)+" like'"+fetchRS.getString(j+1).replace('"','*')+"%'");
}else{
if((Columns.get(j).toString()).equalsIgnoreCase("CUSTOMER_NAME")){
parameters.append(" and customer_id $'"+fetchRS.getString("customer_id")+"'");
}else{
parameters.append(" and "+Columns.get(j)+"$'"+fetchRS.getString(j+1)+"'");
}
 
}//end if
headers.append(" "+Headings.get(j)+"$"+fetchRS.getString(j+1)+(j%2==0?"<BR>":" "));
}//End of IF
}// End of For
out.println("</tr>");
recCount++;
tempValue = fetchRS.getString(1);
firstLoop = false;
}//END OF WHILE
}catch(Exception exp){

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Record In Jsp & back end differ for same query Posted: Nov 6, 2003 3:16 PM
Reply to this message Reply
I am not sure whether I can help you with this. Sorr about it

Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Re: Record In Jsp & back end differ for same query Posted: Nov 9, 2003 8:37 PM
Reply to this message Reply
Its ok thanks for your help,however this problem is solved I dont know why this happened but how this was corrected was nothing from front end (JSP). But the data updated at beckend .but still im wondering how can this happen if anyone have any idea about the backend can please let the forum know about the reason .

Flat View: This topic has 7 replies on 1 page
Topic: any software that can convert *.java file to *.exe file ?? Previous Topic   Next Topic Topic: Need Help wit JList

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use