aspose file tools*
The moose likes JDBC and the fly likes Extra rows when displaying resultSet in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Extra rows when displaying resultSet in browser" Watch "Extra rows when displaying resultSet in browser" New topic
Author

Extra rows when displaying resultSet in browser

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
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!!




[Thumbnail for 2.JPG]


[Thumbnail for 1.JPG]

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

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

Joined: May 13, 2009
Posts: 99
Paul,
I am sorry... this is the query in my DB.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

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

Joined: May 13, 2009
Posts: 99
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
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

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

Joined: May 13, 2009
Posts: 99
Paul,
If it has no place how can I use it and obtain the same functionality of Java
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

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.
David Richard
Greenhorn

Joined: Nov 07, 2011
Posts: 2

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 ------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extra rows when displaying resultSet in browser