473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

retrieving data from the resultset into the jsp page

283 100+
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 14561
r035198x
13,262 8TB
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 100+
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 8TB
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 100+
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 8TB
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 100+
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 8TB
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 100+
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 8TB
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 100+
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 8TB
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 100+
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 8TB
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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
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...

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.