473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

retrieving data from the resultset into the jsp page

283 Contributor
hi frnds,
im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class-
Expand|Select|Wrap|Line Numbers
  1.                for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 s11 = resultset.getString(2);
  5.                 s12 = resultset.getString(3);
  6.             }
  7.             resultset.close();
how do i retrieve the result of s10,s11,s12 in my jsp page?? wat changes do i have to do in my code??(i.e form bean and jsp page)??
wud appreciate ur thoughts...thanx in advance..
regards,
ajos
Sep 18 '07 #1
13 14565
r035198x
13,262 MVP
hi frnds,
im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class-
Expand|Select|Wrap|Line Numbers
  1.                for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 s11 = resultset.getString(2);
  5.                 s12 = resultset.getString(3);
  6.             }
  7.             resultset.close();
how do i retrieve the result of s10,s11,s12 in my jsp page?? wat changes do i have to do in my code??(i.e form bean and jsp page)??
wud appreciate ur thoughts...thanx in advance..
regards,
ajos
You can write that same code in a JSP. Or extract the results in some other class and then send the results to the JSP as an attribute.
Sep 18 '07 #2
ajos
283 Contributor
You can write that same code in a JSP. Or extract the results in some other class and then send the results to the JSP as an attribute.
hi r035198x,
thanx for ur reply yet again.....ive opted for the 2nd solution i.e using setAttribute
this is wat ive done-

Expand|Select|Wrap|Line Numbers
  1. s10 = resultset.getString(1);
  2.                 httpservletrequest.setAttribute("s10", s10);
  3.                 s11 = resultset.getString(2);
  4.                 httpservletrequest.setAttribute("s11", s11);
  5.                 s12 = resultset.getString(3);
  6.                 httpservletrequest.setAttribute("s12", s12);
  7.  
  8.  
is this the right way?
how do i call this in my jsp page--->which is like this

[HTML]<font face="Tahoma">"+ s11 +"</font>[/HTML]
[HTML]<font face="Tahoma">" +s12+ "</font>[/HTML]
regards,
ajos
Sep 18 '07 #3
r035198x
13,262 MVP
hi r035198x,
thanx for ur reply yet again.....ive opted for the 2nd solution i.e using setAttribute
this is wat ive done-

Expand|Select|Wrap|Line Numbers
  1. s10 = resultset.getString(1);
  2.                 httpservletrequest.setAttribute("s10", s10);
  3.                 s11 = resultset.getString(2);
  4.                 httpservletrequest.setAttribute("s11", s11);
  5.                 s12 = resultset.getString(3);
  6.                 httpservletrequest.setAttribute("s12", s12);
  7.  
  8.  
is this the right way?
how do i call this in my jsp page--->which is like this

[HTML]<font face="Tahoma">"+ s11 +"</font>[/HTML]
[HTML]<font face="Tahoma">" +s12+ "</font>[/HTML]
regards,
ajos
Expand|Select|Wrap|Line Numbers
  1. <%
  2. String s10 = (String)request.getAttribute("s10");
  3. %>
Sep 18 '07 #4
ajos
283 Contributor
Expand|Select|Wrap|Line Numbers
  1. <%
  2. String s10 = (String)request.getAttribute("s10");
  3. %>
hi,
im getting the values of that particular columns as null....this is wat i did

<%String s11=(String)request.getAttribute("s11"); %>
<font face="Tahoma"> <%=s11 %> </font>
i think this is right...wats wrong with this????
Sep 18 '07 #5
r035198x
13,262 MVP
hi,
im getting the values of that particular columns as null....this is wat i did


i think this is right...wats wrong with this????
How did you call the JSP in the code?
Sep 18 '07 #6
ajos
283 Contributor
How did you call the JSP in the code?
ok this is how i called in the jsp page-->

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%String s11=(String)request.getAttribute("s11"); %>
  3. <font face="Tahoma"> <%=s11 %> </font>
  4.  
  5.  
where <%=s11%> is the values that will be displayed...
regards,
ajos
Sep 18 '07 #7
r035198x
13,262 MVP
ok this is how i called in the jsp page-->

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%String s11=(String)request.getAttribute("s11"); %>
  3. <font face="Tahoma"> <%=s11 %> </font>
  4.  
  5.  
where <%=s11%> is the values that will be displayed...
regards,
ajos
No that's not what I'm asking. Are you calling the JSP from a servlet? You should be. Otherwise if you are not using servlets then you should use the other option I talked about earlier.
Sep 18 '07 #8
ajos
283 Contributor
No that's not what I'm asking. Are you calling the JSP from a servlet? You should be. Otherwise if you are not using servlets then you should use the other option I talked about earlier.
my code,-->
Expand|Select|Wrap|Line Numbers
  1. for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 httpservletrequest.setAttribute("s10", s10);
  5.                 s11 = resultset.getString(2);
  6.                 httpservletrequest.setAttribute("s11", s11);
  7.                 s12 = resultset.getString(3);
  8.                 httpservletrequest.setAttribute("s12", s12);
  9.             }
  10.  
this is in the action class...
im calling getAttribute in my jsp page
Sep 18 '07 #9
r035198x
13,262 MVP
my code,-->
Expand|Select|Wrap|Line Numbers
  1. for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 httpservletrequest.setAttribute("s10", s10);
  5.                 s11 = resultset.getString(2);
  6.                 httpservletrequest.setAttribute("s11", s11);
  7.                 s12 = resultset.getString(3);
  8.                 httpservletrequest.setAttribute("s12", s12);
  9.             }
  10.  
this is in the action class...
im calling getAttribute in my jsp page
You should call the JSP from the code using
Expand|Select|Wrap|Line Numbers
  1. request.getRequestDispatcher("JSPPathAndName.jsp").include(request, response);
That way you pass the attributes to the JSP as well. You can't call this JSP by just double clicking it because then it wont have the attributes set.
Sep 18 '07 #10
ajos
283 Contributor
That way you pass the attributes to the JSP as well. You can't call this JSP by just double clicking it because then it wont have the attributes set.
You should call the JSP from the code using
Expand|Select|Wrap|Line Numbers
  1. request.getRequestDispatcher("JSPPathAndName.jsp").include(request, response);
im already forwarding the control to the jsp page using
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
the method u mentioned above,wud had gone well if i use servlets...but
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
also does wat RequestDispatcher does..
i better check my database records coz in the form bean ive set the value as null eg-private xyz=null; and since that is printing i think its ok...correct me if im wrong...

regards,
ajos
Sep 18 '07 #11
r035198x
13,262 MVP
im already forwarding the control to the jsp page using
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
the method u mentioned above,wud had gone well if i use servlets...but
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
also does wat RequestDispatcher does..
i better check my database records coz in the form bean ive set the value as null eg-private xyz=null; and since that is printing i think its ok...correct me if im wrong...

regards,
ajos
Yep check with println statements to see that you are forwarding non null values in the first place.
P.S I'm going to have to move this to the Java forum as it doesn;t have much to do with MySQL
Sep 18 '07 #12
ajos
283 Contributor
Yep check with println statements to see that you are forwarding non null values in the first place.
P.S I'm going to have to move this to the Java forum as it doesn;t have much to do with MySQL
hi r035198x,
i think its right.i checked the database,and to my disbelief the records entered in the table wasnt enough hence the queries requirement wasnt matching....
thanx for the help yet again.....(i think this will never stop!!!)
regards,
ajos
Sep 18 '07 #13
r035198x
13,262 MVP
hi r035198x,
i think its right.i checked the database,and to my disbelief the records entered in the table wasnt enough hence the queries requirement wasnt matching....
thanx for the help yet again.....(i think this will never stop!!!)
regards,
ajos
What will never stop?
Sep 18 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: cliff | last post by:
I am in the process of developing an application and would like to hide the query strings in the URLs. I want to POST data to a page then validate the data. If there is an error I have to send data...
5
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If...
3
by: Jakob Petersen | last post by:
Hi, I need to increase the speed when retrieving data from a hosted SQL Server into VBA. I'm using simple SELECT statements. How important is the speed of my Internet connection? (I have...
0
by: DC01 | last post by:
I have added a new measure successfully into the normal cube. I then add it to the virtual cube and reprocess all cubes. I can browse the normal cube successfully. Then when I try and browse the...
1
by: hanusoft | last post by:
This is an example of Inserting and Retrieving data from xml file. private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ...
1
by: hanusoft | last post by:
This is an example of Inserting and Retrieving data from xml file. private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ...
4
by: smartin | last post by:
Hi, I'm having problem retrieving data from an SQL stored procedure. I tried debugging but it wont give a the reason for the error. it just throws an exception after executing cmd.ExecuteNonQuery...
3
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method...
10
vikas1111
by: vikas1111 | last post by:
Hi All Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on...
7
by: splendid9 | last post by:
Problem in retrieving data from a XML file.......this is my code- protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.