| | |
How to retrieve data multiple row data from oracle database rable and show it on jsp
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
How to retrieve data multiple row data from oracle database rable and show it on jsp
0
#1 Oct 7th, 2008
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
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
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
•
•
Join Date: Aug 2006
Posts: 137
Reputation:
Solved Threads: 11
Re: How to retrieve data multiple row data from oracle database rable and show it on jsp
0
#2 Oct 8th, 2008
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?
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?
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
Re: How to retrieve data multiple row data from oracle database rable and show it on jsp
0
#3 Oct 8th, 2008
•
•
•
•
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?
can you more elaborate the above?
Thanks and Regards
harshal
•
•
Join Date: Aug 2006
Posts: 137
Reputation:
Solved Threads: 11
Re: How to retrieve data multiple row data from oracle database rable and show it on jsp
0
#4 Oct 15th, 2008
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:
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:
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:
Hope this makes sense and helps.
Java Syntax (Toggle Plain Text)
package packagename; class TwoColBean { String a, b; public TwoColBean(String a, String b) { this.a = a; this.b = b; } public getA() { return a; } ... }
<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)
public List getData() throws SQLException { List dataList = new ArrayList(); // create empty list // query database > getDAtaQuery is a PreparedStatment object ResultSet results = getDataQuery.executeQuery(); // get rows from result and create a TwoColBean and add to list while ( results.next() ) { TwoColBean d = new TwoColBean(); d.setId(results.getString( 1 )); d.setTimestamp(results.getString( 2 )); dataList.add(d); } // return list of "QuotationBeans" to calling jsp page return quotationList; }
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)
List quoteList = databaseBean.getData(); Iterator dListIterator = dList.iterator(); TwoColBean d; while ( dListIterator.hasNext() ) { d = ( TwoColBean) dListIterator.next(); %> <%-- end scriptlet; insert fixed template data --%> <tr> <td><%= d.getColA() %></td> <td><%= d.getColB() %></td> </tr> <% // continue scriptlet } // end while %> <%-- end scriptlet --%>
Hope this makes sense and helps.
![]() |
Other Threads in the JSP Forum
- Previous Thread: Project suggestion
- Next Thread: how to connect jsp page with acess databse
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write





