• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Extra rows when displaying resultSet in browser

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a small web app and sometimes when I display a query, I get rows that are duplicated. However when I run the same query on my DB i do not get anything duplicated, does anybody konw why is this happening...

this is my code in my .jsp page



This is what i get when i run my query on my DB. (2.JPG)

This is the output in my browser (1.JPG)...as you can see, the rows inside the red rectangle are the extra ones.

Can anybody help!!

2.JPG
[Thumbnail for 2.JPG]
Result from DB
1.JPG
[Thumbnail for 1.JPG]
Output in browser
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mentioned the "same query"... but you didn't show us the query you are executing.

In fact almost none of the relevant information is in your post. You've got some code which is executing a query and returning something which is apparently a ResultSet.
Is that code thread-safe?
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
I am sorry... this is the query in my DB.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. And as I suggested, we should be looking at the code which processes that query and produces the ResultSet, not the code you posted.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
I found my error. if you take a look at the code in my .jsp the problem is from the colums i am getting the value of the row. both of them are from column 1 instead of 1 & 2. Also the name of the colums are differente..

this is the correct string for my query in my .jsp file

"SELECT * FROM public.\""+provList[i]+"_"+request.getParameter("yrOption")+"\" WHERE \"Cuenta\" = '"+R3.getString(2)+"' AND \"Subcuenta\" = '"+R3.getString(1)+"';"

THANKS FOR THE HELP!
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, no, I couldn't see that. Java code in a JSP is horribly unreadable and unmaintainable. You should really stop doing that; this kind of code has no place in a JSP.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
If it has no place how can I use it and obtain the same functionality of Java
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a strange question. Your code is already Java. So your question sounds as if you think the only way to run Java code is by embedding it in a JSP.

But obviously that isn't the case. The professional way to implement those requirements would be to write a servlet which extracts the data from the ResultSet and puts it
into a list of some kind of object which represents a row in your output. Add that list to the request as a request attribute and forward to a JSP which simply copies the data
from the list to the output HTML.
 
Greenhorn
Posts: 2
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did like to join the recent discussion on excluding scriptlets from JSP for alternate ways -
I do agree with the trouble with code readability and maintenance on using java code in JSP.
1) But I am thinking which of the approaches has better performance - though including every thing in one JSP file has the issue above mentioned - is not it faster at performance than a layer code which has to go through various classes to get the same job done.
2) also i found few constraints where alternate way like the JSTL tag libraries or Struts libraries are still not well versatile to meet every real world requirement -
ex: i did not find a way to iterate a collection of collection in either JSTL (c:foreach) or Struts(logic:iterate) libraries recursively. Both c:foreach and logic:iterate can extract values in list but not from a list of list.
Any though you would like to put on this problem with out using srciplets.

--David Rich ------
 
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic