Results 1 to 4 of 4
- 04-20-2010, 04:44 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 27
- Rep Power
- 0
Loop through an Array and invoke SQL command
Hi Guys,
I've got a big problem with these JSP/JSPX pages. I'm sure you people can help me.
Basically I am passing an array of strings from a Java servlet to a JSP page where I am trying to go through the array using 'forEach' loop and for each element, invoke a MYSQL command.
The array is called "Websites".
Here is my code:
<c:forEach var="e" begin="0" step="1" end=${Websites.length}>
<sql:query var="table">
select SUM(usability) as number from ${Websites[e]};
</sql:query>
.......
I have two main problems, firstly in the ForEach Tag, "Website.length" is not working, it returns SQL error at run time.
secondly in the MySql command, "${Website[e]}" is not working too, it returns SQL error at run time as well.
PLease Please help because I have been spending so much time on this.
- 04-20-2010, 05:13 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Posting exceptions might help.
I only ask because if Websites is simply an array there is no way it'll throw a SQLException in the for-each loop.
I would also suggest that you do the SQL in the servlet and simply pass all the necessary data into the JSP page. It's be a lot easier to debug, if nothing else. Data gathering sholdn't really be the responsibility of the JSP.
- 04-23-2010, 05:03 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 27
- Rep Power
- 0
Thanks for reply, but Toll, your answer does not make sense to me (sorry i am not very good with jsp), this is my exact problem that I don't know whether my forEach loop is correct or not, that was actually my question, is my forEach loop correct?
- 04-25-2010, 12:14 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Finding a the max value of the array using a for loop
By soccer_kid_6 in forum New To JavaReplies: 1Last Post: 04-11-2010, 11:25 PM -
[SOLVED] Errors with project: specify array size by the value in first command-line a
By jhrh95 in forum New To JavaReplies: 22Last Post: 01-05-2009, 01:03 AM -
How do I create an array with every cycle of a loop?
By blackhole8746 in forum New To JavaReplies: 3Last Post: 05-07-2008, 07:49 AM -
Need another program with and if-else, array, and for loop
By Zebra in forum New To JavaReplies: 2Last Post: 05-05-2008, 01:56 PM -
Timing array loop performance
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks