Paged query results in a JSP page
Hi All,
I have a requirement to display only a small number of records (say 50) in a JSP page at a time from a database query that returns more than 10,000 records. For accessing all the other records I have to provide links from the same page. I should be able to go to the first, last, next & previous sets of records at any time. Database is Oracle and the table I am using to query doesn't have a serial number column. Any easy way? Thanks Raj
Hi Raj,
There are two ways to handle it.
One is to fetch the entire set of record from the Database and store the details in a Container which has session level context. But if the fetched size is higher then Session cannot hold that much amount of data.
Alternatively you can go about fetching fixed chunks of data from the
Database(preferably of size 50 to 100). This can be achieved using SQL queries. I have done this and seems to work pefectly in situations where large data available in Database has to be displayed pagewise to the users. (U will find the query in AskTom site of Oracle Corporation).
Please revert back if any further help is needed in this regard.
Ilamparithi
Similar Messages
-
Managing a query result through several web pages
Hi,
I wonder what's the best way to manage a query result through several web
pages in the following context.
The query result is large and needs to be available through several web
pages. The user can scroll forward and backward through the pages.
One can :
- rerun the query at each web request and use random access
- run the query once for the first request, keep the pm and the query
somewhere (in a singleton class for example with a key in the HTTP
session) and use random access for handling the other requests (the
problems I see are to keep a connection for each user in this use case and
to decide when to close the previously mentioned objects)
- rerun the query at each web request, including in the filter a test on a
field and an ordering to start the results from the last one displayed
(being able to specify the maximum number of rows desired would be nice).
Thanks for any advice or suggestion.
Regards.I think Frank's suggestion is probably the best tradeoff between memory
consumption (which would be high if you were to store the enire query
result in the session) and performance (which might be hurt if you
re-issue the query every time).
Note that Kodo 3.0 will provide a getObjectsById(Object[] ids) method
that should help in quickly instantiating a page of query results.
Query result limiting is currently under discussion for inclusion in the
JDO specification. We may have something for this in an upcoming Kodo
release (although not for 3.0).
In article <[email protected]>, Frank Riley wrote:
[email protected] (Patrice) wrote in
news:[email protected]:
Hi,
I wonder what's the best way to manage a query result through several
web pages in the following context.
The query result is large and needs to be available through several
web pages. The user can scroll forward and backward through the pages.
One can :
- rerun the query at each web request and use random access
- run the query once for the first request, keep the pm and the query
somewhere (in a singleton class for example with a key in the HTTP
session) and use random access for handling the other requests (the
problems I see are to keep a connection for each user in this use case
and to decide when to close the previously mentioned objects)
- rerun the query at each web request, including in the filter a test
on a field and an ordering to start the results from the last one
displayed (being able to specify the maximum number of rows desired
would be nice).For our paging code, we convert the query result to a list of object ids
(using pm.getObjectId()). We store this list on the session and only
instantiate the objects we need for a particular page (using
pm.getObjectById()). When a user does something that could possibly
change the query result, we rerun the query and replace the list on the
sesssion.--
Marc Prud'hommeaux [email protected]
SolarMetric Inc. http://www.solarmetric.com -
JDBC query theme in a JSP page
Hi, everyone
I tried to write JDBC query theme in a JSP page at MapViewer, but it did not work.
The following is the codes.
1.JDBC theme in a map request in XML
<theme name="jdbc_theme_contour">
<jdbc_query
datasource="spatial10g"
jdbc_srid="8703"
spatial_column="geom"
render_style="C.RED">
Select geom from contour where time='01-JUL-07'
</jdbc_query>
</theme>
2. JDBC theme in a JSP request.
"<theme name=\"jdbc_theme_contour\" >\n" +
" <jdbc_query \n" +
" jdbc_srid=\"" + srid + "\"\n" +
" datasource=\"" + dataSource + "\"\n" +
" spatial_column=\" geom \"\n" +
" render_style=\"C.RED\" >\n" +
" SELECT geom from contour where time='01-JUL-07' \n" +
" </jdbc_query> \n" +
" </theme> \n" +
I do not know whether the second form is right or not. I did not display the JDBC query in MapViewer. Does anyone know the second form is right? or Maybe give me a right form in a JSP request. (contour is a table , geom is the column of geometry attribute in contour)
GengshengHi
Here is the map request in JSP
// Construct a map request
mapRequest = "xml_request=" +
"<?xml version=\"1.0\" standalone=\"yes\" ?>\n" +
"<map_request \n" +
// " title=\"" + title + "\"\n" +
" datasource=\"" + dataSource + "\"\n" +
" basemap=\"" + basemap + "\"\n" +
" width=\"" + width + "\"\n" +
" height=\"" + height + "\"\n" +
" bgcolor=\"#FFFFFF\" >\n" +
" format=\"PNG_URL\" >\n" +
" <center size=\"" + size + "\">\n" +
" <geoFeature>\n" +
" <geometricProperty typeName=\"center\">\n" +
" <Point>\n" +
" <coordinates>\n" +
" " + cx + ", " + cy + "\n" +
" </coordinates>\n" +
" </Point>\n" +
" </geometricProperty>\n" +
" </geoFeature>\n" +
" </center>\n" +
"<themes> \n" +
(flood.equals("true")?
("<theme name=\"jdbc_theme_contour\" >\n" +
" <jdbc_query \n" +
" jdbc_srid=\"" + srid + "\"\n" +
" datasource=\"" + dataSource + "\"\n" +
" spatial_column=\"GEOM\"\n" +
" render_style=\"C.RED\" >\n" +
" SELECT * from contour where time='01-JUL-07' \n" +
" </jdbc_query> \n" +
" </theme> \n") : "") +
(waterdepth.equals("true")?
(" <theme name=\"FLOOD.LINKS\" >\n" +
" </theme> \n") : "") +
" <theme name=\"net_theme\" user_clickable=\"false\"> \n" +
" <jdbc_network_query \n" +
" network_name=\"" + networkName + "\"\n" +
" network_level=\"1\" \n" +
" jdbc_srid=\"" + srid + "\"\n" +
" datasource=\"" + dataSource + "\"\n" +
(showlinks.equals("true")?
(" link_style=\"L.CRM_SROADS\"\n") : "") +
(showlinks.equals("true") && showdir.equals("true")?
(" direction_style=\"M.IMAGE105_BW\"\n" +
" direction_position=\"0.75\"\n" +
" direction_markersize=\"" + dirsize + "\"\n") : "") +
(showlinks.equals("true") && showlklabels.equals("true")?
(" link_labelstyle=\"" + lklbstyle + "\"\n" +
" link_labelcolumn=\"link_id\"\n") : "") +
(shownodes.equals("true") ?
(" node_style=\"M.CITY HALL 4\"\n" +
" node_markersize=\"" + nodesize + "\"\n") : "") +
(shownodes.equals("true") && showndlabels.equals("true")?
(" node_labelstyle=\"" + ndlbstyle + "\"\n" +
" node_labelcolumn=\"" + ndlbcolumn + "\"\n") : "") +
(showpath.equals("true") ?
(" path_ids=\"" + pathid + "\"\n" +
" path_styles=\"L.PH\"\n") : "") +
" asis=\"false\"></jdbc_network_query> \n" +
" </theme> \n" +
(runanalysis.equals("true") &&
(algorithm.equals("DIJKSTRA") || algorithm.equals("ASEARCH")) ?
(" <theme name=\"spath_theme\" user_clickable=\"false\"> \n" +
" <jdbc_network_query \n" +
" network_name=\"" + networkName + "\"\n" +
" network_level=\"1\" \n" +
" jdbc_srid=\"" + srid + "\"\n" +
" datasource=\"" + dataSource + "\"\n" +
" analysis_algorithm=\"" + algorithm + "\"\n" +
" shortestpath_style=\"L.DPH\"\n" +
" shortestpath_startnode=\"" + startnode + "\"\n" +
" shortestpath_endnode=\"" + endnode + "\"\n" +
" shortestpath_startstyle=\"M.STAR\"\n" +
" shortestpath_endstyle=\"M.CIRCLE\"\n" +
" asis=\"false\"></jdbc_network_query> \n" +
" </theme> \n") : "") +
"</themes>\n" +
"</map_request>\n";
in this request, other themes and JDBC network query theme work except the JDBC query theme. I guess the style or format in the following are not right.
" spatial_column=\" geom \"\n" +
" SELECT geom from contour where time='01-JUL-07' \n" +
Anyway, I hope you can give me instructions.
Gengsheng -
How Can I speed up the results on my JSP page with the help of Caching.
I am generating a dropdown listbox by merging an xml file with a style sheet(xsl).
This list box comes up fine without any problems. Now, I am adding some advanced
logic to the
style sheet (xsl) to use the same xml file in a more efficient way. This time
the generation
of the list box is taking much longer (upto 25 seconds) although I get the results
I want.
Is there any way I could speedup this process by using weblogics caching. I know
the process is slowing down
due to the code in the stylesheet. Will caching resolve this issue?. I tried
using
<wl:cache> </wl:cache> on the jsp page generating this listbox but found no improvement.
Any help will be very much appreciated.turn off your phone, unplug your router, leace it off for 30 seconds, and then power it back on and turn the iphone back on
-
How to separate search results onto different jsp pages?
Hi,
I'm using struts framework and I'm a newbie to this technology as well as JSP.
Let's say, this is an online shop portal and a user has decided to search by category for the products he wants. After submitting the search string, the servlet will return a collection of product value objects to the searchResult.jsp.
Since this collection may contain alot of products, I will have to allow the user to choose to view the search results by 5, 10, 20 products etc. Now, how do i divide the collection? Do i have to code this function in the action servlet or at the jsp pages? And how do i code them?I had a similar problem which I resolved by:
1) load results into a ArrayList
2) Have a ValueListHandler with getNextElements(int) & getPreviousElements(int) - see J2EE patterns book for code egs
3) Then I put logic in display jsp along lines of if ->, call ValueListHandler.getNextElements(10), else call ValueListHandler.getPreviousElements(10)
Good luck
Eddie
Hi,
I'm using struts framework and I'm a newbie to this
s technology as well as JSP.
Let's say, this is an online shop portal and a user
r has decided to search by category for the products
he wants. After submitting the search string, the
servlet will return a collection of product value
objects to the searchResult.jsp.
Since this collection may contain alot of products, I
will have to allow the user to choose to view the
search results by 5, 10, 20 products etc. Now, how do
i divide the collection? Do i have to code this
function in the action servlet or at the jsp pages?
And how do i code them? -
Paged query results within a TIle ?
what is the best way to page query results within a Tile
component ?
eg. I have a Tile component with multiple Repeater Image
links supplied via an HTTPService call to a PHP script.
I want to break up the tiled result pages to save loading
time.
Would I load the entire result set into Flex, and then
control how they are viewed by using the horizontal or
verticalScrollPosition property of the Tile container, or perhaps I
could make multiple HTTPService calls for each page of results ?
Any ideas would be much appreciated.What about using the tilelist object for multiple returned
images? You can provide the list as the dataSource to the TileList.
The images are dynamically linked and they are delivered from the
server when they are rendered. That way you could bring down the
url for many images and dynamically link to the images. This would
allow you to bring down many rows at one time. -
Do paging with header on a JSP page
Hi:
We have a data report displayed as a JSP page. The report displays 200 rows of data. We need to print these 200 rows report with a header/title on each page. And our user only wants to hit he Browser print button once. This would have been easy if we don't have to insert the header on each print page. But how can we print this multiple page report with a header? Do we need to use CSS? any help will be appreciated.
reportPrinterOkay bear with me:
Step 1: determine how many rows in a table with a header will print on a single page
Step 2: Create a jsp that breaks your data down into tables of the row size determined above.
For example if the data consists of 1000 rows and 50 rows w/ headers will fit on a page
then the jsp will create 20 tables of 50 rows w/ headers each.
Step 3: Use CSS to put page breaks between the tables.
http://www.htmlgoodies.com/beyond/css_print.html
Step 4: In the original JSP use the HTML LINK tag to link it to the JSP you just created
http://www.gself.com/xbas/head/linking.htm
<link rel="alternative" href="{new JSP url}" type="text/html" media="print" />
Step 5: On the original JSP provide a button that when clicked on will call the JavaScript print function.
Now what should happen is that when the button on the original JSP is clicked the JavaScript print function will be called but instead of the page displayed in the browser being printed the alternative page
in the LINK tag will get printed. This alternative JSP page is formatted to print one table with headers per page.
The only part of this that I have not used in a production web app iss the CSS page break part. The rest of it I know will work. -
To retrieve a query result in to OAF page
I am newbee...........
i have an urgent requirement
*"+TO GET THE RESULT OF QUERY+"* FROM MY DATABASE IN TO MSG TEXT INPUT
item in my page
any sort of help is appreciated
thanx in advance......
DEV
Edited by: Dev586 on Jan 9, 2013 12:29 PMHi,
try {
String result = null;
ResultSet resultset = null;
PreparedStatement stmt = null;
Connection conn = am.getOADBTransaction().getJdbcConnection();
String qry = "select count(employees) INDIANS from employee where empcountry='INDIA'";
stmt = conn.prepareStatement(qry);
resultset = stmt.executeQuery();
if (resultset != null) {
while (resultset.next()) {
if (resultset.getString(1) != null) {
result = resultset.getString(1);
} catch (Exception e) {
e.printStackTrace();
This will give you the output in variable 'result'.
Now you can set its value to the text input field.
--Sushant -
How to call a stored procedure to search db then return results to jsp page
Hi,
Most of what i have said is in the title. Im trying to search a database using a stored procedure that will call the procedure using sql2000 then coming back with the results to the jsp page. all of this is done using JSP web pages. if JAVA example is availabel then let me know.
I need some examples.. I cant seem to find any code that will help.
ThanksUse CallableStatement. You can set parameters with setXXX and registerOutParameter methods. And to fetch results, you can use getXXX methods of it.
-
How to call a stored to search database then return results to jsp page
Hi,
Most of what i have said is in the title. Im trying to search a database using a stored procedure that will call the procedure using sql2000 then coming back with the results to the jsp page. all of this is done using JSP web pages. if JAVA example is availabel then let me know.
I need some examples.. I cant seem to find any code that will help.
ThanksMake use of Callablestatement. You can set parameters to it by registerOutParameters and setXXX methods. And use getXXX methods to get results of procedure.
-
How can I export the query result into access(*.mdb) file?
Dear all:
I want to export the query result displayed in jsp into excel file
and access file. And I have exported the result into excel format successfully, only one line should be added in the head of Jsp:
<%@ page contentType="application/vnd.ms-excel; charset=gb2312" %>
But how can I export it in access(*.mdb) file? I have replaced "excel"
with "access". But it can't achive my goal.
What should I do to achieve my goal?
Thanks!The only reason your Excel export works is that Excel knows how to interpret comma separated values as an input file format. Access has no such beast.
If you absolutely must provide info in an mdb, one solution would be to create an ODBC datasource pointing to an empty mdb, then push data into it using the jdbc:odbc bridge, then make a copy of the file and stream it down to the browser. You may run into some ugly file locking items here - set the ODBC connection so it is not shared, and that might help.
This one is going to be ugly.
I suppose another approach would be to write a simple VB applicatin that uses automation to create an MDB, then stream that file down to the browser from your servlet. That would almost certainly be faster than the ODBC approach.
- K -
Display the "sum(getcount)* in the jsp page??
I've this table in my database:
[ode]
phone ! model ! version ! count
123 abcd sis 1
234 asdfas sis 2
345 werwer jad 6
342 xcvxcv sis 3
678 jlkj jad 2
I want to display the the total number of count on my jsp page using jdbc connection. So, in this case the result should be 14 because the total number of count is (1+2+6+3+2). I know the SQL command as
"select sum(count) from table_name" but how to display the result on my jsp page. Please help me out. I tried but it's not happening......
in advance thanks.......Hi,
look at my answer to your post regarding length of resultset. It is the same here.
Statement stmt = con.createStatement() ;
ResultSet rs = stmt.executeQuery("select sum(MYTABLE.id) from MYTABLE where MYTABLE.ID > 123") ;
rs.next() ;
BigDecimal bdRowCount = rs.getBigDecimal(1) ;select count or select sum return a resultset with one row. You can access this resultset like any other. The row has one field containing a number which you can access as a BigDecimal (like shown above).
It really is not that fdifficult to do. If you have done it with count you can do it with sum, avg etc. The limit is only set by the functions your database provides. You can have something like
select count(*), avg(colname1), sum(colname2),sum(colname3) from table,
which would return a resultset still containing only one row, but within that row 4 fields, each a BigDecimal. -
Help fowarding data to a jsp page
I know your not meant to double post but i was told it would be better if i post this message in here so:
I am trying to create a bean that will connect to a database and bring back data depending on what a user typed into a html form. However i need some help, if the database does not find any data i want to send a message saying something like "no results" to a jsp page which then be displayed, if results are found i then want to pass on these results to another jsp page.
My question is how would i pass on this data / message to a jsp page? Also if more then one piece of data is returned from the database how would i be able to make sure everything is sent to the jsp?In the above code a Servlet, a JavaBean, JDBC and everything else is combined into just one class. That is not how it is.
A Servlet is a Servlet --- it is not a JavaBean ---- So create a dedicated class that is purely a Servlet and does what a Servlet is supposed to do. Taking the tutorial on Servlets will help you understand them better.
A JavaBean is a JavaBean ---- it is not a Servlet --- Create a JavaBean class.
Move the Database Connection code to the Data Access Layer --- this means create separate classes that are meant to only access data.
It is better to learn each individual concept before attempting something more complex.
Also build small code into your class, ---- understand what it's doing then compile it frequently.
I'll give you hints on how you should properly implement an MVC pattern.
JSP Page
This page contains an HTML form , with form fields and a submit button.
In the action attribute of the form you will specify the URL-pattern for the Servlet.
The URL-pattern for the servlet will be defined in web.xml , for example
<form action="/MyFirstServlet" method="post" >
</form>Then create a Servlet , in its package , so for example
com.myapp.servlet.MyFirstServlet.java
Place the servlet file in a proper folder structure in the Java source folder.
When the Servlet it compiled it needs to go under the corresponding folder structure under your applications /WEB-INF/classes/ folder.
Your servlet will look something like this:
package com.myapp.servlet.MyFirstServlet;
//All import statements go here
public class MyFirstServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ......... exceptions {
doPost(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ......... exceptions {
//Process the request here
request.getAttribute("someFormField");
//similarly get all form fields
//Store all fields into a JavaBean
//Then call a method that saves the data to database
saveToDatabase(pass the javabean here);
private void saveToDatabase(SomeJavaBean someJavaBean){
//Over here call a DataAccessObject -- DAO that saves the data
// to the database.
/WEB-INF/web.xml
When you write a servlet you need to define it in web.xml and define a URL mapping also for it in web.xml
JavaBean example
com.myapp.beans.Person.java
package com.myapp.beans.Person;
//whatever import statements (if any) go here
public class Person{
private int age;
private String firstName;
public Person(){} //Every JavaBean must have a default constructor
//Write the Getters and Setters for the private fields above.
//in proper JavaBeans notation as follows
public void setAge(int age){
this.age = age;
public int getAge(){
return this.age;
//Similarly write getter and setter for firstName
}You would then use the above JavaBean to transport data between the database layer and JSP layer via the Servlet.
If you are Saving to the Database , you read the HTML form's data and save it into one JavaBean and then pass the JavaBean to the database layer to be saved. In the Database layer you write JDBC code to save the data.
If you are Reading from the database, you create an ArrayList of JavaBean objects in the database layer using JDBC code and then pass the ArrayList to the Servlet which stores it in the Request, then the servlet forwards control to the JSP which then reads the data from the request.
Most of the above is pseudo code, it is just there to give you an idea about how do this properly in MVC --- you can then read tutorials on each of the above --- for example tutorial on Servlet, tutorial on JDBC, tutorial on Java Classes and then understand them more. -
How include a Servlet into a JSP page?
Hi!!
I need make a combobox with a servlet and place its result into a jsp page.
The servlet is in a package, but when i do: <jsp:include file="sic.view.servlet.ComboServlet" />
tell me that "file attribute isn�t a valid attribute name"
whow can i do to make the combobox whit the servlet and include this into the jsp page??
Thanks!!
PD: Sorry my pour English...Servlets should be mapped to a URL, then you access the servlet via that URL.
The servlet mapping is done in the web.xml (in WEB-INF/ directory of your web application)
<servlet>
<servlet-name>
Combo_S
</servlet-name>
<servlet-class>
sic.view.servlet.ComboServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
Combo_S
</servlet-name>
<url-pattern>
/combo
</url-pattern>
</servlet-mapping>Then you would use:
<jsp:include file="combo" />
to include it.
Make sure the class file gets put in the right package under WEB-INF/classes/ -
How to run servlet from JSP page
A simple JSP page,where I will put a button.And on clicking..it will invoke the servlet and the servlet will send the result to the jsp page...
Please give the instructions with examples...
Thanks in advance...hi,
Create a jsp inside webapps/root
<a href="./howtocode" > click to call servlet </a>and follow the steps
http://forum.java.sun.com/thread.jspa?threadID=5202830
Maybe you are looking for
-
Brand new Macbook Pro not pairing with Apple Keyboard and mouse!
Hi all, I have a brand new Macbook Pro and an older wireless Apple Keyboard and Mouse (that were being previously used with my imac G5). Now I want to use these for this macbook. I am finding that they are being recognised but not pairing up? Do you
-
Issue swapping coordinates of PNG stored in 2D Array
Hi, I'm using the interactive png class found here I'm loading in the the required date from an xml file which is structured like this <?xml version="1.0"?> <theData> <_title_>pictures!</_title_> <_url_>images/</_url_> <slides> <sub image="images.png
-
ihad an older version of photoshop elements where i had collections in the right hand column and on disc i have now opened albums and added new photos but when i try to put them on the disc it says arase the disc and lose all the data, do i have to p
-
OK guys, I'm struggling. I've watched the on-line tutorials, read the white papers (especially "Naming Standardization"), and looked through the help pages. There are so many options for controlling naming that I think I'm lost in the trees trying to
-
I have Studio 8 on my computer ( MS windows xp sp2). I uninstalled all of the programs, through the control panel, in preparation to installing CS3 Web Premium . The control panel indicated that the program was uninstalled but when I checked Windows