Displaying a resultset

hey im new hear and fairly new to JSP. The thing is I want to display a list of records from a database in text boxes. When i open the JSP page the first record in the data base is displayed, when i press the "Last" button the last record in the database is displayed. Also when i press the "First" button the result set goes back to the first record. My problem is that the "Previous" and "Next" buttons dont work properly. The code in the JSP page is as:
<%@ page language = "java" contentType = "text/html"%>
<%@ page language = "java" import = "oracle.jdbc.driver.OracleDriver" %>
<%@ page language = "java" import = "java.sql.*" %>
<%@ page language = "java" import = "java.io.*" %>
<%@ page language = "java" import = "java.util.*" %>
<%@ page language = "java" import = "skip.*" %>
<%
     String Last = request.getParameter("Last");
     String First = request.getParameter("First");
     String Next = request.getParameter("Next");
     String Prev = request.getParameter("Previous");
     String l = (String)session.getAttribute("name");
     ResultSet rs = null;
     GetVenueDetails g = new GetVenueDetails();
     rs = g.getVenueDetails();
     String id = rs.getString("Venue_id");
     String venue = rs.getString("Venue_name");
     String addy = rs.getString("Address");
     String city = rs.getString("City");
     String country = rs.getString("Country");
     String cap = rs.getString("Capacity");
     if(First != null)
          rs.first();
          id = rs.getString("Venue_id");
          venue = rs.getString("Venue_name");
          addy = rs.getString("Address");
          city = rs.getString("City");
          country = rs.getString("Country");
          cap = rs.getString("Capacity");
     if(Last != null)
          rs.last();
          id = rs.getString("Venue_id");
          venue = rs.getString("Venue_name");
          addy = rs.getString("Address");
          city = rs.getString("City");
          country = rs.getString("Country");
          cap = rs.getString("Capacity");
     if(Next != null)
          rs.last();
          id = rs.getString("Venue_id");
          venue = rs.getString("Venue_name");
          addy = rs.getString("Address");
          city = rs.getString("City");
          country = rs.getString("Country");
          cap = rs.getString("Capacity");
     if(Prev != null)
          rs.previous();
          id = rs.getString("Venue_id");
          venue = rs.getString("Venue_name");
          addy = rs.getString("Address");
          city = rs.getString("City");
          country = rs.getString("Country");
          cap = rs.getString("Capacity");
%>
My java class is as follows:
package skip;
import java.sql.*;
import java.util.Properties;
public class GetVenueDetails
     static DBConnection DB = new DBConnection();
     Statement select;
     ResultSet result;
     Connection conn = DB.getConnection();
     public ResultSet getVenueDetails()
     Statement stmt = null;
          try
               stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
               result = stmt.executeQuery("select * from Venue");
               result.beforeFirst();
               result.next();
               System.out.println(result.getInt("Venue_id"));
          catch (SQLException e)
               System.out.print("SQL Exception " + e);
               System.exit(1);
     return result;
     public static void main(String args[])
          GetVenueDetails g = new GetVenueDetails();
          ResultSet rs;
          rs = g.getVenueDetails();
Ive seen a few similar questions on the site regarding such topics but i just cant make sence of them as i am new to JSP and only a college student. Any help would be appreciated.
Paul

hi paulPt,
firstly i would like to suggest dont write :--
String id = rs.getString("Venue_id");
String venue = rs.getString("Venue_name");
String addy = rs.getString("Address");
String city = rs.getString("City");
String country = rs.getString("Country");
String cap = rs.getString("Capacity");
and so on .... in each if block its doesnt looks good. use:-----
if(first!=null)
rs.first();
if(next!=null)
rs.next();
} and so on
and at the end write
String id = rs.getString("Venue_id");
String venue = rs.getString("Venue_name");
String addy = rs.getString("Address");
String city = rs.getString("City");
String country = rs.getString("Country");
String cap = rs.getString("Capacity");
Now Please tell me whats the ur problem is . Is it giving any error or throw any exception or it does not work at all . i will try my best

Similar Messages

  • Displaying Same ResultSet Twice In A JSP Page

    I have a table that lists team names in my database. I'm trying to create a page with 2 dropdown boxes where each lists all the teams in the league (in other words, the data read in from the table). I got the first dropdown box to populate w/ this info. My question is about the 2nd dropdown box:
    Since I already have the ResultSet from the 1st dropdown, I would think it would be a waste to make another DB-read to fill in the 2nd dropdown. However, when I tried to call ResultSet.first() it gave me the error that it was TYPE_FORWARD_ONLY. I checked the documentation for Connection and it looks like there are some overloaded methods for createStatement. However, the API documentation (see below) is pretty confusing. I'm not sure what "resultSetConcurrency" or "resultSetHoldability" I need if I just want to read the same data twice. Can someone point me in the right direction?
    Statement createStatement(int resultSetType, int resultSetConcurrency)
    Creates a Statement object that will generate ResultSet objects with the given type and concurrency.
    Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
    Creates a Statement object that will generate ResultSet objects with the given type, concurrency, and holdability.

    I am also having a very similar problem.
    I am having a table having 20 fileds.some of them r to be displayed in one table
    others in some other table.
    for this i am using a bean which returns a resultset which is then used in jsp page
    for display.But i have to call the javabean method twice which fires the query & returns the resultset.
    I cannot store so many fileds with so many rows of values in list of objects also i do not want to
    fire query twice.
    rs.movefirst() does not work, so what should i do.

  • How to display my ResultSet in a JSP??

    First off, I'm new to Java programming.
    Here's my problem. I have a set of users in my database. I'd like to retrieve all the user ID's (these are integers) from my User-table and display them in a JSP. Now, I realize that my coding below isn't very efficient as it's not exactly a MVC approach. I'm just trying to learn what a ResultSet is and how to manipulate it.
    I send my ResultSet to a JSP by "request.setAttribute("usersId", usersId);" but then I'm not sure what to do in my JSP to actually display my User ID's.
    My code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    try {
    String dbURL = "jdbc:mysql://localhost:3306/heading360";
    String username = "root";
    String password = "";
    Connection connection = (Connection) DriverManager.getConnection(
    dbURL, username, password);
    Statement statement = (Statement) connection.createStatement();
    ResultSet userId = (ResultSet) statement.executeQuery("SELECT UserId FROM User");
    request.setAttribute("userId", userId);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/testUserId.jsp");
    dispatcher.forward(request, response);
    catch (SQLException e) {
    for (Throwable t : e)
    t.printStackTrace();
    }

    flukyspore wrote:
    OK thanks for the quick response.
    I am using using JSP EL to write my JSP's. Still learning JSTL.Bad idea. Learn JSTL.
    I understand everything you're saying, except I can't seem to find the exact approach to load my ResultSet into an object or collection. Could you give me an example of how to do that. My ResultSet is one column of User ID's, they are integers. Something like this:
    private static final String FIND_USER_ID_SQL = "SELECT USER_ID FROM USERS";
    private Connection connection;
    public List<Integer> findUserIds()
        List<Integet> userIds = new ArrayList<Integer>();
        Statement stmt = null;
        ResultSet rs = null;
        try
            stmt = connection.createStatement(sql);
            rs = stmt.executeQuery();
            while (rs.next())
                userIds.add(rs.getInt("USER_ID"));
        catch (SQLException e)
            e.printStackTrace();
        finally
            close(rs);
            close(stmt);
        return userIds;
    }Fill in the blanks.
    %

  • Fast display of ResultSet to web browser

    I am working on refactoring my companies search engine, and a critical component of the search is that the results be displayed very quickly. We have done enourmous work on making the queries fast (under 1 second), but the bottleneck always seems to be how we process the results into HTML and send them to the users web browser.
    Running Tomcat, we currently use a JSP page to pass the search parameters to a Java class that queries the database and generates HTML based on the ResultSet object. The method we use to generate the HTML is very low tech, we simply generate a String that contains HTML along with the data from the ResultSet and print the String out to the users web browser via the PrintWriter object obtained from the session.
    I would like to solicit ideas as to how this process can be improved. What's the absolute fastest way to get ResultSet data transformed into HTML and displayed in the users browser? I'm exploring maybe using the XML, but I haven't found much information about the speed of that technology. One caveat is that the data has to be processed before display,in the sense that if certain flags are set in a row of the ResultSet, that row data should be displayed accordingly.
    We currently do something like this many times:
    String html = "<table>";
    if(resultSet.getInt(3) == SOME_FLAG) {
        html += "<tr><td><font color='red'>resultSet.getString(6)</font></td></tr>";
    html += "</table>";It would be nice if the suggestions would fit into our current Oracle/Solaris/Tomcat/JSP/Servlet architecture, but not a requirement.
    Thank you very much!
    P.S. Sorry if this isn't the right category for this. I labored long and hard deciding which category to post this question under, and this one seemed to be the best fit.

    Check out the FormattedDataSet. It does things similar to what your code does, but is much more flexible AND monitored for performance in with JAMon. Out of the box it can create html tables, list boxes, drop downs, multi selects and html. As a developer you can generate dynamic text to appear any way you dream up.
    Here is some sample code
    FormattedDataSet fds=FormattedDataSet.createInstance();
    // same query vary the formatting. note other types of tabular data are also accepted
    String html=fds.getFormattedDataSet("select * from table", "htmlTable");
    String xml=fds.getFormattedDataSet("select * from table", "xml");
    String csv=fds.getFormattedDataSet("select * from table", "csv");Check out a live demo at http://www.fdsapi.com. Within the next week I hope to have a live demo that allows you to type in queries. You can already download a demo war that has this capability.
    steve - http://www.fdsapi.com - the easiest way to generate dynamic content.

  • Displaying bulky ResultSet page wise, in jsp!

    Hello Guyes,
    I am back to the most asked problem again! I have a massive resultset of 5,000 records and I want to display it page wise in my jsp with giving 'Next' and' Back' buttons. I can open the resultset on each page as it will kill my application and server!
    Pls help and give a simple solution in which I can do it!
    It is very urgent!
    Thanks,
    - Rahul

    USE a Scrollable ResultSet object and put it in the session. Keep a variable that identifies where in the resultset ur pointer is at any point of time.
    Scrollable ResultSets are a feature only available with JDBC 2.0 onwards... so make sure u have THAT first.
    Create a Statement like this...
    Statement st =
    con.createStatement(ResultSet.SCROLLABLE);
    Then run the query n store it in the resultset
    ResultSet rs = st.executeQuery(sql);
    Then move ur pointer to any record u want with methods present in the ResultSet interface:
    relative(int rows) that takes you 'rows' rows ahead.
    absolute(int row) that takes your pointer to the 'row'th ROW.
    Make sure u use 'refreshRow()' so u have the latest content at any point of time. This refreshes the contents in that row. there is also something called refresh() BUT THAT would minimise performace.
    Store this resultset object in the session and call it in each page u want starting with the record number u want to. !!
    Hope this helps... aXe!

  • JOptionPane Won't Display When ResultSet = null

    I wrote the following method to connect to an Access database via JDBC. Everything works properly except for the dialog box. It doesn't show up when the SQL query doesn't return anything. I've tried using the JOptionPane as an if, an else if, and an else without any luck. I know the syntax of the JOptionPane statement is correct, as it works in other parts of the program. Can anyone help? Thanks, Scott
    P.S. I know I should use a do while loop to populate the text fields...this is just a quick and dirty beta program.
         public void database(String query)
              try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              String dataSourceName = "testdatabase";
              String dbURL = "jdbc:odbc:" + dataSourceName;
              Connection con = DriverManager.getConnection(dbURL,"","");
              Statement s = con.createStatement();
              s.execute(query);
              ResultSet rs = s.getResultSet();
                   if (rs != null)
                   while ( rs.next() )
                   field2.setText(rs.getString(2));
                        field3.setText(rs.getString(3));
                        field4.setText(rs.getString(4));
                        field5.setText(rs.getString(5));
                        field6.setText(rs.getString(6));
                        field7.setText(rs.getString(7));
                        field8.setText(rs.getString(8));
                        field9.setText(rs.getString(9));
                        field10.setText(rs.getString(10));
                        field11.setText(rs.getString(11));
                        field12.setText(rs.getString(12));
                   if (rs == null)     JOptionPane.showMessageDialog(null, "UPC not found!");
                   s.close();
              con.close();
         catch (Exception err)
              System.out.println("ERROR: " + err);
         }

    I changed the line to:
    if(! rs.next()) JOptionPane.showMessageDialog(null,
    "UPC not found!");
    ...and now the dialog box pops up every time, even if
    there is data. Did I do something wrong with the
    syntax?Well no.. except that by the time you check you have already iterated through the result set and next returns false.
    I was thinking about something like this (and please in future use the code tags for pretty formatting like below... it makes it easier to read and the forum software will "eat" some of your code without it sometimes)
    boolean hasResults = false; // new line
    while ( rs.next() )
        hasResults = true; // there was at least one row
        field2.setText(rs.getString(2));
        field3.setText(rs.getString(3));
        field4.setText(rs.getString(4));
        field5.setText(rs.getString(5));
        field6.setText(rs.getString(6));
        field7.setText(rs.getString(7));
        field8.setText(rs.getString(8));
        field9.setText(rs.getString(9));
        field10.setText(rs.getString(10));
        field11.setText(rs.getString(11));
        field12.setText(rs.getString(12));
    if (!hasResults) JOptionPane.showMessageDialog(null, "UPC not found!");

  • Displaying the ResultSet from and sql database into a java Table in the sam

    i seriously need help in displaying the contents of my sql database into a table im my java application when someone types a query into a field provided..
    thanks guys !!

    What kind of help do you need.
    Are you stuck at some point of your code?
    Is you code not working?
    Or do you want us to write the code?

  • Date based Resultset and Date display

    Hi
    I have two jsp pages. In first page user selects a Date and name, based on that 2nd jsp display a resultset in a table. I want to Display Selected name and Date on 2nd Page. I done it for name and unable to show the Date and query is also to be modified.
    Here is code for my two jsp pages:
    first.jsp
      <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@ include file="DataSource.jsp" %>
    <html>
    <head>
    <title>abcd</title>
    <script type="text/javascript" language="javascript">
    function HTML(p){
    if(!p){
    /*default*/
    p='A action align alt B background Base bgcolor BIG BLINK BODY border bordercolor bordercolordark bordercolorlight Br cellpadding cellspacing checked color cols colspan compact content dir DIV enctype face FONT FORM H1 H2 H3 H4 H5 H6 HEAD height Hr href hspace HTML I id Img Input lang language leftmargin LI marginheight marginwidth maxlength Meta method name NOSCRIPT noshade nowrap OL onblur onchange onclick onfocus onload onmouseout onmouseover onreset onselect onsubmit onunload OPTION P PRE profile readonly rows rowspan SCRIPT SELECT size SMALL SPAN src start STRIKE STYLE style SUB SUP TABLE target TD TEXTAREA TH TITLE title topmargin TR TT type U UL valign value vspace width wrap'
    String.prototype.write=function(){
    document.write(this);
    return this
    String.prototype.alert=function(){
    window.alert(this);
    return this
    String.prototype.status=function(){
    window.status=this;
    return this
    var x=[
    function(W){var q=String.fromCharCode(34);return ' x='+q+((typeof(W)!='undefined')?W:'x')+q}/*attr*/,
    function(W){return '<x'+((typeof(W)!='undefined')?W:'')+' />'}/*tag*/,
    function(W){return '<x'+((typeof(W)!='undefined')?W:'')+'>'+this+'</'+'x>'}/*container*/,
    function(W){var o='<x'+((typeof(W)!='undefined')?W:'')+' />';return o+this.join(o)}/*tags*/,
    function(W){var o='<x'+((typeof(W)!='undefined')?W:'')+'>';var c='</'+'x>';return o+this.join(c+o)+c}/*containers*/
    var j=[];
    var f=0;
    var a=p.split(' ');
    var t,u,l;
    for(var i=0;i<a.length;i++){
    t=a;
    u=t.toUpperCase();
    l=t.toLowerCase();
    if(t==l){
    /*attr*/
    j[f]='window.'+u+'='+x[0]
    else if(t==u){
    /*container;containers*/
    j[f]='String.prototype.'+u+'='+x[2]+';Array.prototype.'+u+'='+x[4]
    else{
    /*tag;tags*/
    j[f]='window.'+u+'='+x[1]+';Array.prototype.'+u+'='+x[3]
    /*specific*/
    j[f]=j[f].replace(/x/g,l);
    f++
    window.status='HTML() bookmarklet library: Copyright (c) 2002-'+(new Date()).getFullYear()+', by Richard Edwards. ['+f+' tag/attrs added] ';
    /*implement!*/
    eval(j.join(';'))
    HTML();
    </script>
    <script type="text/javascript" language="javascript">
    function init(){m='January February March April May June July August September October November December'.split(' ');wd='Su M Tu W Th Fr Sa'.split(' ');lom=[31,28,31,30,31,30,31,31,30,31,30,31];sz=25;js='javascript';fn=[function(F){},function(F){DATE=new Date(F.date.value);if(isNaN(DATE.valueOf())){DATE=new Date()};M=DATE.getMonth();D=DATE.getDate();Y=DATE.getFullYear();lom[1]=28;if((Y%/**/4==0)&&((Y%/**/100>0)||(Y%/**/400==0))){lom[1]++}},function(F){if(D>lom[M]){D=lom[M]};F.date.value=(M<9?'0':'')+(1.0+M)+'/'+(D<10?'0':'')+D+'/'+Y;dv.value=F.date.value;if(opener.Page){opener.document.forms[0][dv.name].value=F.date.value}},function(){F=this.form;fn[1](F);M=this.selectedIndex;fn[2](F);fn[0](F)},function(){F=this.form;fn[1](F);D=this.value;fn[2](F);fn[0](F)},function(){F=this.form;fn[1](F);Y=this.value;fn[2](F);fn[0](F)},function(F){fn[1](F);var f=new Date(Y,M,1);var x=1-(f.getDay());for(var i=0;i<49;i++){F.d[i].value=(i<7?wd[i]:'');F.d[i].onclick=this;};for(var i=1;i<=lom[M];i++){w=Math.floor((i-1)/7);n=7+i-x;F.d[n].value=i;F.d[n].onclick=fn[4];if(i==D){F.d[7+i-x].focus()}};for(var i=0;i<F.m.length;i++){F.m[i].selected=(i==M)};F.m.onchange=fn[3];F.y.value=Y;F.y.onchange=fn[5];F.y.onblur=fn[5];fn[2](F)}];fn[0]=fn[6]};init();function popCal(datevalue){if(!datevalue){dv={name:'Today',value:(new Date())}}else{dv=datevalue};var c=ALIGN('center')+HEIGHT(sz);var h=(m.OPTION().SELECT(NAME('m'))+INPUT(TYPE('text')+SIZE(4)+NAME('y'))+INPUT(TYPE('hidden')+NAME('date')+VALUE(dv.value))).TD(COLSPAN(7)+c);var b=INPUT(TYPE('button')+NAME('d')+STYLE('width:'+sz+';height:'+sz)+WIDTH(sz)+c);var r=[b,b,b,b,b,b,b].TD(WIDTH(sz*7)+c);h=[h,r,r,r,r,r,r,r].TR(c).TABLE(BORDER('0')+CELLSPACING('0')+CELLPADDING('0')+c).FORM(NAME('frm')+ACTION(js+'://'));h+=(init+';init();dv=opener.dv;fn[0](document.forms.frm);').SCRIPT(LANGUAGE(js)+TYPE('text/'+js));window.open('','cal'+(new Date()).valueOf(),'height='+sz*9+',width='+sz*8).document.write(h)};
    </script>
    </head>
    <body bgcolor=lightblue>
    <center><h1>xyz</h1></center>
    <hr>
    <br>
    <p>
    <p>
    <p>
    <p>
    <h4>Select a date: </h4>
    <script type="text/javascript" language="javascript">
    (INPUT(NAME("DV")+READONLY())+INPUT(TYPE("button")+VALUE("Calendar..")+ONkLICK("popCal(this.form.DV)"))).FORM().write();
    </script>
    <p>
    <p>
    <br>
    <form method=post action="second.jsp">
    <sql:transaction dataSource="${example}">
         <sql:query var="Power">
              select unique trader_name from exchange_deal where unit_of_measure='mwh'
         </sql:query>
    </sql:transaction>
    <h4><p>Select a Trader:
         <select Name = "TraderDrop">
         <c:forEach var="row" items="${Power.rows}">
    <option size="20"><c:out value="${row.Trader_name}"/></option>
    </c:forEach>
         </select>
    <p>
    </h4>
    <br>
    <input type="submit" value="SUBMIT"/>
    <input type="reset" value="CANCEL"/>
    </form>
    </body>
    </html>
    Second jsp
      <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@ include file="DataSource.jsp" %>
    <html>
    <head>
    <title>abc</title>
    </head>
    <body bgcolor=lightblue>
    <center><h1>xyz</h1></center>
    <hr>
    <form name="input" action="pqr.jsp"
    method="get">
    <c:set var="s" value="${param.TraderDrop}" />
    <h3>Trader : <c:out value="${s}" /></h3>
    <c:set var="d" value="${param.date}" />
    <h3>Trade Date: <c:out value="${d}" /></h3>
    <sql:transaction dataSource="${example}">
    <sql:query var="Power">
         SELECT DEAL_ID, DEAL_TYPE, EXCHANGE_NAME, HUB_NAME, ORGINATING_APPLICATION, PRODUCT_ID, TAKER_COMPANY FROM ENYWARE.EXCHANGE_DEAL where TRANSACTION_TIMESTAMP > sysdate - 3 and trader_name = '<c:out value="${s}" />'
    </sql:query>
    </sql:transaction>
    <table border="1">
    <%-- Get the column names for the header of the table --%>
    <tr>
    <c:forEach var="columnName" items="${Power.columnNames}">
    <th><c:out value="${columnName}"/></th>
    </c:forEach>
    </tr>
    <tr>
    <c:forEach var="column" items="${row}">
    <td><c:out value="${column.value}"/></td>
    </c:forEach>
    </tr>
    </c:forEach>
    </table>
    </form>
    </body>
    </html>
    I am using JavaScript calendar for entering date in a Text box.
    Please review code and help me.
    Thanks in Advance
    Surya

    Anitha123 wrote:
    Hi
    Thanks for your reply..
    We execute our application using a batch file which holds the main class file to be executed as below :
    batch file content as below :
    set PATH=.\_jvm\bin
    set JAVA_HOME=.\_jvm
    set CLASSPATH=.\_jvm\lib\rt.jar;.\_jvm\lib\itext.jar
    java -cp %CLASSPATH%;.\classes xx.yy.zz.Ourmainclass
    Here how can i set the time zone as users time zone? we don't use any manifest file for our application..can you please guide me on the same..Very Good...Then here is your answer..
    set PATH=.\_jvm\bin
    set JAVA_HOME=.\_jvm
    set CLASSPATH=.\_jvm\lib\rt.jar;.\_jvm\lib\itext.jar
    java -Duser.timezone=Asia/Calcutta -cp %CLASSPATH%;.\classes xx.yy.zz.OurmainclassIf this will solve your problem.. don't forget to reward duke stars...please..

  • How do display ResultSet in multiple pages ? Please help !!!

    Hi all,
    I want to display the ResultSet of my JSP in multiple pages.I want to group them as a set of 10 records on one page and so on the output
    displayed on further pages in a set of 10 records per page.
    Is there any Simple way to do that ?
    Any response will be highly appreciated.
    Thanks in advance for any help.
    regards,
    savdeep

    Haii
    From the result set put your values inside any util objects like vector or hastable and make use of them to show the result in the page..
    And again it depends on the requirement..
    regards
    Shanu

  • Using Vector to display ResultSet on multiple pages

    Hi all,
    I want to use Vector for Displaying the ResultSet in multiple pages for my JSP.
    Can anybody assist me on how to display Resultset on multiple pages by using Vectors.
    Thanks for any help in advance.
    regards,
    savdeep

    Haii Pls go through the code
    Vector v=new Vectior()
    while(rs.next())
       v.add(rs.getString(column name));
    v //vector is readyyyyyregards
    Shanu

  • Display java.sql.ResultSet

    Hi !
    How can I display a ResultSet with MetaInformations (ColumnName as Table Header) in a JSF Table ? The main problem is that I don't know the columns name.
    Anyone could help me on this ?

    RTFM or Google

  • Problem in displaying a table.

    Hi all,
    I have a simple jsp page which connects to a bean file. The bean file is suppose to return a ResultSet and display it in a form of a table with multiple entries.
    However, what I would like to achieve is that if the ResultSet returns nothing (i.e. no records in the database) I would like to display a message information the user.
    This is what i have done:
    <% ResultSet rs = user.getProduct(userID); %>
    <% if (!rs.next()) { %>                  
    There are no products.
    <% } else {%>
    These are your products.
    <table>
    <tr>
    <td>Product</td>
    <td>Price</td>
    <tr>
    <% while(rs.next()) {          
    String product = rs.getString("Product");
    String price = rs.getString("Price");
    %>
    <tr>
    <td> <%= product %> </td>
    <td> <%= price %> </td>
    </tr>
    <% } // end of while statement %>
    <% } // end of if else statement %>
    It is able to display the ResultSet, however, because i have two rs.next() to get the rs, the curser in the database have jump to the next line, causing the final while(rs.next) to return data starting from the second line.
    I don't know if the question is clear enough, but hope to get some help on this.
    Thanks!
    Yong

    Hi,
    just a fast answer, I cannot stay a lot...
    I think is not the best solutions, but you can use a counter instead of the "if(!rs.next)" statement...
    <% ResultSet rs = user.getProduct(userID); %><% int recordSetSize = 0;%>
    <% //if (!rs.next()) { %>                  
    //There are no products.
    <% //} else {%>
    <% while(rs.next()) {if (recordSetSize == 0){
    These are your products.
    <table>
    <tr>
    <td>Product</td>
    <td>Price</td>
    </tr><% }%>
    <% //while(rs.next()) {          recordSetSize++;
    String product = rs.getString("Product");
    String price = rs.getString("Price");
    %>
    <tr>
    <td> <%= product %> </td>
    <td> <%= price %> </td>
    </tr>
    <% } // end of while statement %><%if (recordSetSize > 0){%>
    </table>
    <%}else{%>
    There are no products.
    <%}%>
    <% //} // end of if else statement %>I hope be useful.
    Bye.

  • Displaying results from a database query using servlets

    I have this HTML form where users can search a MS Access database by entering a combination of EmployeeID, First name or last name. This form invokes a Java Servlet which searches the database and displays the results as an HTML page. I am giving the user the choice of displaying 3, 5 or 10 results per page. I want to know how to do that using servlets. If a particular search results in 20 results, the results should be displayed in sets of 3, 5 or 10 depending on the user's choice. If the user makes a choice of 5 results per page then 4 pages should be displayed with a "next" and "previous" button on each page. I want to know how this can be done.

    Arun,
    I'm not sure how to do this using JSP as I have not worked on JSP.
    But I can give you a hint on how to do this within normal java class as I've used this in my current project.
    In your core class/bean that generates the entire resultset, you need to run a loop that will scan through the desired number of records in the resultset.
    To do this, you have to have skip and max parameter in your URL.
    Somthing like http://server.com/myservlet?skip=0&max=10 to display first 10 records, http://server.com/myservlet?skip=10&max=10 to display next 10 records. The <next>parameter would be fed in by the user by a simple form in your web-page. If you need to hold this <max-num-of-recs-per-page> param, you can store it in a cookie (since this is nothing crucial piece of info, don't need to use session obj etc...cookie will do) and get the value each time you display the resultset.
    So, essentially, suppose you are at the first page and you wish to show 10 recs at a time. The link for "Next" button would be http://server.com/myservlet?skip=10&max=10
    when at the second page, you'll have
    "priv" button as http://server.com/myservlet?skip=0&max=10 and
    "next" button as http://server.com/myservlet?skip=20&max=10 and so on...
    hope this makes sense..
    Shantanu

  • How do I handle large resultsets in CRXI without a performance issue?

    Hello -
    Problem Definition
    I have a performance problem displaying large/huge resultset of data on a crystal report.  The report takes about 4 minutes or more depending on the resultset size.
    How do you handle large resultsets in Crystal Reports without a performance issue?
    Environment
    Crystal Reports XI
    Apache WebSvr 2.X, Jboss 4.2.3, Struts
    Java Reporting Component (JRC),Crystal Report Viewer (CRV)
    Firefox
    DETAILS
    I use the CRXI thick client to build my report (.rpt) and then use it in my webapplication (webapp) under Jboss.
    User specifies the filter criteria to generate a report (date range etc) and submits the request to the webapp.  Webapp  queries the database, gets a "resultset".
    I initialize the JRC and CRV according to all the specifications and finally call the "processHttpRequest" method of Crystal Report Viewer to display the report on browser.
    So.....
    - Request received to generate a report with a filter criteria
    - Query DB to get resultset
    - Initialize JRC and CRV
    - finally display the report by calling
        reportViewer.processHttpRequest(request, response, request.getSession().getServletContext(), null);
    The performance problem is within the last step.  I put logs everywhere and noticed that database query doesnt take too long to return resultset.  Everything processes pretty quickly till I call the processHttpRequest of CRV.  This method just hangs for a long time before displaying the report on browser.
    CRV runs pretty fast when the resultset is smaller, but for large resultset it takes a long long time.
    I do have subreports and use Crystal report formulas on the reports.  Some of them are used for grouping also.  But I dont think Subreports is the real culprit here.  Because I have some other reports that dont have any subreports, and they too get really slow displaying large resultsets.
    Solutions?
    So obviously I need a good solution to this generic problem of "How do you handle large resultsets in Crystal Reports?"
    I have thought of some half baked ideas.
    A) Use external pagination and fetch data only for the current page being displayed.  But for this, CRXI must allow me to create my own buttons (previous, next, last), so I can control the click event and fetch data accordingly.  I tried capturing events by registering event handler "addToolbarCommandEventListener" of CRV.  But my listener gets invoked "after" processHttpRequest method completes, which doesnt help.
    Some how I need to be able to control the UI by adding my own previous page, next page, last page buttons and controlling it's click events. 
    B) Automagically have CRXI use a javascript functionality, to allow browser side page navigation.  So maybe the first time it'll take 5 mins to display the report, but once it's displayed, user can go to any page without sending the request back to server.
    C) Try using Crystal Reports 2008.  I'm open to using this version, but I couldnt figureout if it has any features that can help me do external pagination or anything that can handle large resultsets.
    D) Will using the Crystal Reports Servers like cache server/application server etc help in any way?  I read a little on the Crystal Page Viewer, Interactive Viewer, Part Viewer etc....but I'm not sure if any of these things are going to solve the issue.
    I'd appreciate it if someone can point me in the right direction.

    Essentialy the answer is use smaller resultsets or pull from the database directly instead of using resultsets.

  • Database query ResultSet from servlet to JSP page

              Hi there,
              I have an Access 2000 database. I am running Apache and Tomcat on Windows Me.
              I would like to know if it is possible for me to use a Servlet to search the
              database (I know this bit is possible!), but then I would like the servlet to
              forward to a jsp page which will then display the ResultSet that the servlet has
              retrieved, i.e. when forwarding from a servlet to a jsp, is it possible for the
              jsp page to have access to the servlet's data? I know that it gets access to
              the response and request objects, but what about a ResultSet?
              Sorry it this sounds a little silly - i am a bit of a newbie.
              Thanks in advance for your help,
              SJ
              

    HttpServletRequest.setAttribute let's you share data for a particular
              request. When you call forward you can store the resultset in the request.
              Make sure your JSP does close the result set though, because what you are
              trying to do doesn't sound good :)
              If you want to share data across the session, take a look at the HttpSession
              object.
              read through the servlet specification, it is fairly easy to read and will
              give you all the info you need
              Filip
              ~
              Namaste - I bow to the divine in you
              ~
              Filip Hanik
              Software Architect
              [email protected]
              www.filip.net
              "SJ" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Hi there,
              >
              > I have an Access 2000 database. I am running Apache and Tomcat on Windows
              Me.
              > I would like to know if it is possible for me to use a Servlet to search
              the
              > database (I know this bit is possible!), but then I would like the servlet
              to
              > forward to a jsp page which will then display the ResultSet that the
              servlet has
              > retrieved, i.e. when forwarding from a servlet to a jsp, is it possible
              for the
              > jsp page to have access to the servlet's data? I know that it gets access
              to
              > the response and request objects, but what about a ResultSet?
              >
              > Sorry it this sounds a little silly - i am a bit of a newbie.
              >
              > Thanks in advance for your help,
              >
              > SJ
              

Maybe you are looking for

  • Windows 8.1, Military CAC, Dual Persona PIV Cert, DEE-mail Access Problem

    I am not able to access the military e-mail system, Defense Enterprise E-mail (DEE) from my new computer.  My new computer is a Dell Venue 11 Pro Tablet that runs Windows 8.1 with the latest updates.  In addition, hardware wise, I have a CAC (Common

  • Function Module - Customer Installment Payment Due

    Hello, I am trying to create a payment due report for our customers. We use installment payment terms for our customers. Therefore, when run at the end of September 2011 this report has to only show the invoice amount, tax and discount that is due as

  • Printing multiple 'sheets' per page, using adobe pdf printer

    I've got a number of PDFs that are scanned books, and they were scanned 2 pages at a time, and then OCRed What I'd like to be able to do is re'print' the file to a new PDF file (so that the OCRed text remains searchable in the new file), in a5, so th

  • 6220 camera pics not stored in gallery

    Hi, Anybody who can help me troubleshoot this. The images folder is lost and all pictures taken by my Nokia 6220 is not stored even if I add an "Images" folder. Everytime I take pictures, the filename goes on and on but I can't find where those pictu

  • How to close pop up error messages

    Hi, I am running a sequence that contains sub-sequences. Sometimes an error may occur and a 'System Level Exception Handling' pop up error message will appear. I want the pop up window to be recognised so that my sequence doesn't hang waiting for a u