File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Is there any one who can help me...Please? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Is there any one who can help me...Please?" Watch "Is there any one who can help me...Please?" New topic
Author

Is there any one who can help me...Please?

Bhaskar Duvvuri
Greenhorn

Joined: Nov 30, 2003
Posts: 7
Here is my query in my jsp
dbconn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
sql = dbconn.prepareStatement("SELECT AdStore.AdId, " +
"AdStore.AdType, " +
"AdStore.AdDesc FROM AdStore " +
"WHERE (((AdStore.AdStatus)='" + activeStatus + "'))");
ResultSet rs = (ResultSet) sql.executeQuery();
int recnum = 0;
while(rs.next())
{
System.out.println("Got more rows\n");
recnum ++;
out.println("<tr>");
out.println("<font color=\"blue\" size =\"3\"></size></font>");
out.println("<td>" + rs.getInt(1) + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getString(3) + "</td>");
out.println("<td><A HREF=?action=PlaceBid.jsp&ad=\" + rs.getInt(1) + \">Bid</A></td>");
System.out.println("The link is: \n" +
"<td><A HREF=?action=PlaceBid.jsp&ad=\" + rs.getInt(1) + ">Bid</A></td>");
}
Now I want to provide a link to another page with each of the records fetched, and send that id as part of my url to the new page. The funny thing is, if I simply assign as follows:
int ad1 = rs.getInt(1);
within the while loop, my query breaks off right after fetching the first row. Not only that, no matter what I do, if I assign the value of any of the fields fetched to any variables/do any formatting, the query stops after fetching only one record with a SQLState of Null (No data found). But the fact is I have 3 rows in my table. If I remove the line with HREF from abvoe code, I get to see all three rows. With the code (as copied in place), I see only one row.
I am sooooo desperate for help. Come on! Someone take pity on me.
Uma Balu
Ranch Hand

Joined: Aug 22, 2003
Posts: 61
Hi,

You are using rs.getInt(1) twice. Instead of that, use, rs.getInt(1) only once, get the value and store it in a temp variable and use the temp variable in all other places.
Hope this helps you,
Uma...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Sunny, please read the private message that I just sent to you.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Posted on behalf of Bhaskar:

Thanks Uma!
But my problem is that within the rs.getNext() loop, if I assign rs.getInt(1) to any variable, then the loop breaks off after bringing in the first record. I am at a total loss as to why this happens. If I replace all out.println with a html block, even then it just bombs. I even tried to put the database fields fetched into an array, but again, it stops right after fetching the first record.
I just experimented with what you suggested and the url is coming as follows:
http://localhost:9090/self/jsp/ViewAd.jsp?action=PlaceBid.jsp&ad="
where c:\tomcat\tomcat4.1.28\self\jsp is the directory where I have the jsps located.
BTW! This is not a real system, where in I have to worry about security. This is my learning project with the jsp's accessing my local access database.

[ December 03, 2003: Message edited by: Bear Bibeault ]
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Hi Bhaskar Duvvuri :
I hope you are the same Sunny that has been sending me private messages. It is easier for me or anyone else to assist you here on javaranch than thru the use of private messages.
Now I want you to try this code.
Jus copy it and paste on your JSP page, tell us what the outcome is and lets go from there.
dbconn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
sql = dbconn.prepareStatement("SELECT AdStore.AdId, " +
"AdStore.AdType, " +
"AdStore.AdDesc FROM AdStore " +
"WHERE (((AdStore.AdStatus)='" + activeStatus + "'))");
ResultSet rs = sql.executeQuery();
int recnum = 0;
while(rs.next())
{
System.out.println("Got more rows\n");
recnum ++;
String id = rs.getString(1) ;
out.println("<tr>");
out.println("<font color=\"blue\" size =\"3\"></size></font>");
out.println("<td>" + id + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getString(3) + "</td>");
out.println("<td><A HREF='PlaceBid.jsp?ad=\" + id + \"'>Bid</A></td>");
System.out.println("The link is: \n" +
"<td><A HREF='PlaceBid.jsp?ad=\" + id + \"'>Bid</A></td>");
out.println("</tr>") ;// not very necessarily since the start of a <tr> automatically closes the previous <tr>
}
I do not see the start and end of your table tags. If they are not there please add them.
If this does not work, you might have to remove everything like font and colors and have just plain html, that will make things less clustered and easier to spot errors. After we might have had a working html then you can add your fonts and colors. Do not be discouraged by this initial difficulties. With the help of those of us at JavaRanch and hard work on your part, you sure will overcome this initail difficulties.
Let us know which error if any that is generated this time around.
Bhaskar Duvvuri
Greenhorn

Joined: Nov 30, 2003
Posts: 7
First of all I aplogize if I inconvenienced you by sending a personal message. I just was replying to your earlier mail. Secondly, yes! I am the same person. I guess they didn't like my name, which is what I am called. Anyhow, I followed your suggestion and used the code you sent. The url is working (i.e. it takes me to the target page), but the value for id is not showing up. Here is the url:
http://localhost:9090/self/jsp/PlaceBid.jsp?ad="%20+%20iD%20+%20"
the value of ad is not showing. Yes! I can see all three records without a problem.
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Good. Atleast we got the main problem knocked out of the way. The second problem which has to do with the id not showing is nothing but problem with the quotes. I will get to that in a minute.
It was 'nt like you inconvenienced me by sending private messages but it is easier tackling this thing here, so that errors on my part could be spotted by others, that was why I was encouraging you to rectify the naming issue.
I will take a second look at the line with the id variable and get back to you in a minute.
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Ok; I actually tested this particular code before posting to make sure it is a working code.
Just replace the line out.println("<td><A HREF='PlaceBid.jsp?ad=\" + id + \"'>Bid</A></td>"); with
this out.println("<td><A HREF='PlaceBid.jsp?ad=" + id + "'>Bid</A></td>");
It worked for me so it should work for you and that solves the whole problem.
Good Luck;
anselm.
 
Consider Paul's rocket mass heater.
 
subject: Is there any one who can help me...Please?