943,895 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 6197
  • JSP RSS
Oct 7th, 2008
0

How to retrieve data multiple row data from oracle database rable and show it on jsp

Expand Post »
Currently I am working on one form development using Java. In JSP page I retrieved the data from table using F9 keys i.e for any input field variable available in JSP page, once I pressed the F9 key, all the related data is displayed in the popup window. Once I select particular item , item description would be displayed on page and related item code was used to store the particular item in database. In this form I used add new row as a button to add a new row (this is for the automatic row increment purposes) it work fine for adding the item into table/
Now in next task I have to retrieve all this data from particular table which is available in multiple row format in table . How can I retrieve all this data for particular dynamic rows.
Here with I have attached the JSP page which is showing adding multiple row in dynamically. Also I am attaching related servlet page used to retrieve the data .
Any suggestion is highly appreciated .




Thanks,
Harshal
Attached Files
File Type: txt JSP_page.txt (34.4 KB, 405 views)
File Type: txt Servlet.txt (33.9 KB, 277 views)
Last edited by peter_budo; Oct 7th, 2008 at 10:07 am. Reason: Attached code move to files as it does break down view in Firefox
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Oct 8th, 2008
0

Re: How to retrieve data multiple row data from oracle database rable and show it on jsp

I'm a little confused and that's probably because I'm not sure what a dynamic row is? I looked at your attachments which are quite long when opened...

I noticed you're using JavaScript. Is there a problem with using Java embedded code? The way that I've been taught to retrieve data from a database is to encapsulate the each row within a Java Bean to form an ArrayList of Beans where a Bean is just a class that has get and set methods. I can describe this method further but I'm not sure if this is what you're looking for?

Actually that leads me to my question to your question... could the above mentioned method not work for you?
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Oct 8th, 2008
0

Re: How to retrieve data multiple row data from oracle database rable and show it on jsp

Click to Expand / Collapse  Quote originally posted by PoovenM ...
I'm a little confused and that's probably because I'm not sure what a dynamic row is? I looked at your attachments which are quite long when opened...

I noticed you're using JavaScript. Is there a problem with using Java embedded code? The way that I've been taught to retrieve data from a database is to encapsulate the each row within a Java Bean to form an ArrayList of Beans where a Bean is just a class that has get and set methods. I can describe this method further but I'm not sure if this is what you're looking for?

Actually that leads me to my question to your question... could the above mentioned method not work for you?
Hi PoovenM;

can you more elaborate the above?
Thanks and Regards
harshal
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Oct 15th, 2008
0

Re: How to retrieve data multiple row data from oracle database rable and show it on jsp

Hi there, I'm not sure which part you wanted me to elaborate on? Suppose you ran an SQL query that retrieved row that had two columns, colA and ColB. You'd then create a Java Bean that abstracts this:
Java Syntax (Toggle Plain Text)
  1. package packagename;
  2. class TwoColBean
  3. {
  4. String a, b;
  5. public TwoColBean(String a, String b)
  6. {
  7. this.a = a;
  8. this.b = b;
  9. }
  10. public getA()
  11. {
  12. return a;
  13. }
  14. ...
  15. }
So the Bean class would just encapsulate the data of those two columns (assuming they were String objects) thus a since Bean stores a single row (since each row consists of two columns). You can use a Java Bean (just like any class) by using the JSP tag:
<jsp:useBean id = "dataBean" scope = "request" class = "packagename.TwoColBean" />

You should look up that if you're unfamiliar with the tag. Of course you'd only do this if you wanted to store data into your database using the bean. To output the data, you'd simply import the class:
<%@ page import = "packagename.TwoColBean" %>

Next you'd query the database (probably from another Bean that's responsible for process database requests) and process each row of the ResultSet and store the values into a List of TwoColBean:
java Syntax (Toggle Plain Text)
  1. public List getData() throws SQLException
  2. {
  3. List dataList = new ArrayList(); // create empty list
  4.  
  5. // query database > getDAtaQuery is a PreparedStatment object
  6. ResultSet results = getDataQuery.executeQuery();
  7.  
  8. // get rows from result and create a TwoColBean and add to list
  9. while ( results.next() ) {
  10. TwoColBean d = new TwoColBean();
  11. d.setId(results.getString( 1 ));
  12. d.setTimestamp(results.getString( 2 ));
  13. dataList.add(d);
  14. }
  15.  
  16. // return list of "QuotationBeans" to calling jsp page
  17. return quotationList;
  18. }

So in your JSP you'd query your database (using a proper mechanism like a Bean) using the above method call and you'd get your list. Then to display the list:

jsp Syntax (Toggle Plain Text)
  1. List quoteList = databaseBean.getData();
  2. Iterator dListIterator = dList.iterator();
  3. TwoColBean d;
  4.  
  5. while ( dListIterator.hasNext() ) {
  6. d = ( TwoColBean) dListIterator.next();
  7.  
  8. %> <%-- end scriptlet; insert fixed template data --%>
  9.  
  10. <tr>
  11. <td><%= d.getColA() %></td>
  12. <td><%= d.getColB() %></td>
  13. </tr>
  14.  
  15. <% // continue scriptlet
  16.  
  17. } // end while
  18.  
  19. %> <%-- end scriptlet --%>

Hope this makes sense and helps.
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Project suggestion
Next Thread in JSP Forum Timeline: jsp uploading





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC