Unix Technical Forum

newbie: query problem from jsp page

This is a discussion on newbie: query problem from jsp page within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi all, I'm writing html in a while loop in a jsp page. Unfortunately, although I'm getting 3 results ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:07 PM
Mike
 
Posts: n/a
Default newbie: query problem from jsp page

Hi all,
I'm writing html in a while loop in a jsp page. Unfortunately,
although I'm getting 3 results back from my first database query (I
tested for
this), only the first one is output, so i only get one set of html
tags output instead of three.
Is this something to do with my nested queries?
Thanks for help,
Mike

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
StringTokenizer token = new StringTokenizer(dataInfo);

Connection myConnect = DriverManager.getConnection("JDBC:ODBC:" +
token.nextToken(),token.nextToken(),token.nextToke n());
Statement myStatement = myConnect.createStatement();

String myQuery = "select * from forums";
myStatement.executeQuery(myQuery);
ResultSet myResults = myStatement.getResultSet();

while (myResults.next()){
int forumID = myResults.getInt("forumID");
String forumTitle = myResults.getString("forumTitle");
String forumDescr = myResults.getString("forumDescr");

%>

<TR>
<TD width="41" height=50 align=middle vAlign=center
class=row1><IMG height=25 alt="Bullet Point" src="pics/bullet.gif"
width=32></TD>
<TD width="495" height=50 class=row1><SPAN
class=forumlink><a href="forum.jsp?f=<%=forumID%>"><%=forumTitle%></a><BR></SPAN>
<SPAN class=genmed><%=forumDescr%></SPAN></TD>

<%
String threadQuery = "select threadID from threads where forumID
='"+forumID+"'";
myStatement.executeQuery(threadQuery);
ResultSet threadResult = myStatement.getResultSet();
int threadCount = 0;
while (threadResult.next()) threadCount++;

String postQuery = "select postID from posts";
myStatement.executeQuery(postQuery);
ResultSet postResult = myStatement.getResultSet();
int postCount = 0;
while (postResult.next()) postCount++;

String lastPostQuery = "select top 1 userName, submitDate from
posts where forumID = '"+forumID+"' order by submitDate desc";
myStatement.executeQuery(lastPostQuery);
ResultSet lastPostResult = myStatement.getResultSet();
String userNm = null;
Timestamp submitDate = null;
while (lastPostResult.next()){
userNm = lastPostResult.getString("userName");
submitDate = lastPostResult.getTimestamp("submitDate");
}
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy
HH:mm:ss z");
String readableDate = sdf.format((java.util.Date)submitDate);
%>

<TD class=row2 vAlign=center align=middle height=50><SPAN
class=gensmall><%= threadCount %></SPAN></TD>
<TD class=row2 vAlign=center align=middle height=50><SPAN
class=gensmall><%= postCount %></SPAN></TD>
<TD class=row2 vAlign=center noWrap align=left
height=50><SPAN class=gensmall><%= readableDate %><BR><%=
userNm%></SPAN></TD>
<%
if (canEdit){ // modify and remove buttons
%>
<TD class=row2 vAlign=center noWrap align=center><img
src="pics/modify.gif" width="44" height="15">&nbsp;<img
src="pics/remove.gif" width="44" height="15"></TD>
<%
}
%>

</TR>

<%
} // while
%>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:42 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com