How to display information from database using drop down list in JSP?

Hi all.
Like the tile above suggest, I'm having difficulty in obtaining the data as well as displaying them in a drop down list.
For example: If i were to have the following in my database:
SerialNo Food
1 Bread
2 Milk
3 Butter
The drop down list should look like the following:
[Bread][\/]
[Milk]
[Butter]
How do i go around coding it in JSP?
Thanks in advance.
C.K

Hai Please try the following code
You have to make some changes according to your system i am using
MSSqlserver Driver change the class name and the connection string
for your need
<HTML>
<HEAD>
<%@ page language="java" import="java.sql.*"%>
<LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>ListDrop.jsp</TITLE>
<%!Connection con;
     %>
</HEAD>
<BODY>
<select>
     <%
          try {
               Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");\\Here you specify the Class Nale
               con = DriverManager
                         .getConnection(
                                   "jdbc:microsoft:sqlserver://javaserver:1433;DatabaseName=karthi",
                                   "sa", "sa");\\here Connection string
               ResultSet rs;
               Statement st = con.createStatement();
               rs = st.executeQuery("select SerialNo,Food from Foods");
               while (rs.next()) {
%>
     <option value='<%= rs.getString("SerialNo") %>'><%= rs.getString("Food")%></option>
     <%
          } catch (Exception e) {
               e.printStackTrace();
%>
</select>
</BODY>
</HTML>

Similar Messages

  • How to display items from database using catagorylookupdroplet

    Hi everyone,
    i want to know how to display items from database using catagorylookup droplet. if anybody have any code snippet please share it.
    Thanks in advance,

    <dsp:droplet name=".................../CategoryLookup">
         <dsp:param name="id" param="itemId"/>
         <dsp:oparam name="output">
              <dsp:valueof param="element.displayName"/>
                   <%-- This is show the Child Category --%>
                   <dsp:droplet name="......................./ForEach">
                   <dsp:param name="array" param="element.childCategories"/>
                   <dsp:oparam name="outputStart">Child Categories</dsp:oparam>
                   <dsp:oparam name="output">
                        <dsp:a href="">//bydefault it will take its own file's name
                             <dsp:param name="itemId" param="element.repositoryId"/>                                                                                          <dsp:valueof param="element.displayName"/>
                        </dsp:a>
                   </dsp:oparam>                                             
                   </dsp:droplet>
                   <%-- This is show the Child Product --%>          
                   <dsp:droplet name=".............../ForEach">
                        <dsp:param name="array" param="element.childProducts"/>
                        <dsp:oparam name="outputStart">Child Products</dsp:oparam>
                                  <dsp:oparam name="output">
                                       <dsp:droplet name="................/ProductLookup">
                                            <dsp:param name="id" param="itemId"/>
                                            <dsp:param name="elementName" value="Prod"/>
                                            <dsp:oparam name="output">
                                                 <dsp:getvalueof id="img102" param="Prod.smallImage.url" idtype="java.lang.String">
                                                      <dsp:img height="250" width="250" src="<%=img102%>"/>
                                                 </dsp:getvalueof>
                                            </dsp:oparam>
                                       </dsp:droplet>
                                       <dsp:a href="productView.jsp">
                                            <dsp:param name="itemId" param="element.repositoryId"/>
                                            <dsp:valueof param="element.displayName"/>
                                       </dsp:a>
    Hope this helps.
    -RMishra

  • RE: Using Drop-Down List in Express Application

    The easiest way to do this is to define a domain for Gender that maps to
    a droplist widget. ForteExpress will then automatically display the
    widget in any ArrayWindow or FormWindow in which Gender appears. (I
    don't think outlinefields support this widget.) There is a documented
    customization for adding SQL to the domain to automatically fill it, but
    we've found this to be a performance drag. What we usually do is cache
    this type of list information on the client, usually by loading it into
    arrays of listelement in a service object at user logon. The list is
    then ready to go whenever a window needs it, and you can set the element
    list of the droplist in PostOpenInit or wherever it seems appropriate.
    From: David Wilbur[SMTP:[email protected]]
    Sent: Wednesday, February 26, 1997 2:21 PM
    To: [email protected]
    Subject: Using Drop-Down List in Express Application
    To: [email protected]
    cc:
    Subject: Using Drop-Down List in Express Application
    On an Express generated Form window I want to use a drop-down list to
    define the list of valid values for a database field. The underlying
    database field could have a datatype of either integer or character.
    For example, on the database we have a Gender column defined. I want to
    use a drop-down list that displays descriptions of "Male" and "Female" for
    allowed database values of "M" and "F". The Gender column is updateable on
    the window.
    Any suggestions on the best way to do this? Would we need to do anything
    different on Array windows?
    David Wilbur email: [email protected]
    University of Windsor phone: 519-253-4232 ext. 2779
    Windsor, Ontario Canada

    Hai Please try the following code
    You have to make some changes according to your system i am using
    MSSqlserver Driver change the class name and the connection string
    for your need
    <HTML>
    <HEAD>
    <%@ page language="java" import="java.sql.*"%>
    <LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
    <TITLE>ListDrop.jsp</TITLE>
    <%!Connection con;
         %>
    </HEAD>
    <BODY>
    <select>
         <%
              try {
                   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");\\Here you specify the Class Nale
                   con = DriverManager
                             .getConnection(
                                       "jdbc:microsoft:sqlserver://javaserver:1433;DatabaseName=karthi",
                                       "sa", "sa");\\here Connection string
                   ResultSet rs;
                   Statement st = con.createStatement();
                   rs = st.executeQuery("select SerialNo,Food from Foods");
                   while (rs.next()) {
    %>
         <option value='<%= rs.getString("SerialNo") %>'><%= rs.getString("Food")%></option>
         <%
              } catch (Exception e) {
                   e.printStackTrace();
    %>
    </select>
    </BODY>
    </HTML>

  • Using Drop-Down List in Express Application

    To: [email protected]
    cc:
    Subject: Using Drop-Down List in Express Application
    On an Express generated Form window I want to use a drop-down list to
    define the list of valid values for a database field. The underlying
    database field could have a datatype of either integer or character.
    For example, on the database we have a Gender column defined. I want to
    use a drop-down list that displays descriptions of "Male" and "Female" for
    allowed database values of "M" and "F". The Gender column is updateable on
    the window.
    Any suggestions on the best way to do this? Would we need to do anything
    different on Array windows?
    David Wilbur email: [email protected]
    University of Windsor phone: 519-253-4232 ext. 2779
    Windsor, Ontario Canada
    -----------------------------------------------

    Hai Please try the following code
    You have to make some changes according to your system i am using
    MSSqlserver Driver change the class name and the connection string
    for your need
    <HTML>
    <HEAD>
    <%@ page language="java" import="java.sql.*"%>
    <LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
    <TITLE>ListDrop.jsp</TITLE>
    <%!Connection con;
         %>
    </HEAD>
    <BODY>
    <select>
         <%
              try {
                   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");\\Here you specify the Class Nale
                   con = DriverManager
                             .getConnection(
                                       "jdbc:microsoft:sqlserver://javaserver:1433;DatabaseName=karthi",
                                       "sa", "sa");\\here Connection string
                   ResultSet rs;
                   Statement st = con.createStatement();
                   rs = st.executeQuery("select SerialNo,Food from Foods");
                   while (rs.next()) {
    %>
         <option value='<%= rs.getString("SerialNo") %>'><%= rs.getString("Food")%></option>
         <%
              } catch (Exception e) {
                   e.printStackTrace();
    %>
    </select>
    </BODY>
    </HTML>

  • Missing Export and Use Drop Down Lists

    I cannot export my .mov files to any format other than .mov as the Export and Use drop down lists are missing. When I go to File > Export the text for Export and Use are there followed by blank gray space as if the drop down lists never existed.
    I just upgraded to Pro today and had infrequently used QuickTime Player previously. I have the most current version 7.6.5. The other functions appear to be working normally, but I am not a "familiar user" so I can't say for sure.
    Any ideas?

    Well I could not copy & paste the text from the Movie Inspector, so I have typed it below (except for the complete source info).
    Source: C:\....Filename.MOV
    Format: 16-bit Integer (Little Endian), Mono, 44.100 KHz
    MPEG-4 Video, 1280 x 720, Millions
    Movie FPS: 30.01
    Playing FPS: 30.01
    Data Size: 8.16 MB
    Data Rate: 6.99 mbits/sec
    Current Time: 00:00:00.00
    Duration: 00:00:09.80
    Normal Size: 1280 x 720 pixels
    Current Size: 1280 x 720 pixels
    I have also downloaded a couple of iPod hip-hop ad movies (.mov) and they have the same problem (no export drop-down lists), so I don't believe it is the movie format.
    I have not tried to uninstall/reinstall QuickTime Pro yet, but wonder if I should....

  • How to display data from Database individually??? Anyone can help ?

    HI,
    i i had select a row of data from database using ,
    /* Query * From Table RESOURCEORDER where po = selected no and project = selected project */
         public ResultSet getAllData() throws SQLException
         getConnection();
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
         return rs;
    After that , how do i display the data individually ?
    Eg select data is ('projectA','7891203-1', '10-4-2005','lcd',2000,'121-45217-8','electrical','pending','donwong')
    i want to display them individually, like this in a page
    Projectname: /* should display the Project A*/
    P.O no:
    Date:
    Order:
    Cost:
    Acc no:
    Type:
    status:
    Orderedby:
    Can anyone help ? cos i'm new to JSP ......Thanks alot!!!!!
    Regards,
    khim

    I assume PO being a unique key, will always return 1 row from db.
    public String[] getAllData() throws Exception
    getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
    String [] returnValue = new String[9];
    while(rs.next())
    returnValue[1] = rs.getString("colname");
    returnValue[2] = rs.getString("colname");
    ///and so on
    return returnValue;
    }Once you get that you could individually view it by setting a loop to run through the returned array.
    Hope it helps

  • Pre-Populating Text fields from a Data drop down list using SQL Server

    I'm currently trying to update some of our internal forms which are word based or a basic PDF form you fill in by yourself.
    I'm connecting to our SQL server as there are databases stored there for an internal bit of software that hold information
    I can use to fill in parts the form.
    I have a data drop down list that is dynamically linked to the SQL databass and allows you to select a Project Number from that database, what
    I want to do after this is selected is to automatically populate some text fields with the Project name, Account handler and other fields held in the
    database.
    I've had a look online to see if there is a solution but haven't really found anythig that is similar (although I am new to LC so may have seen it
    and not realised) and my Java is non existant.
    Has anyone tried this and able to point me in the right directions?
    I'm using LiveCycle ES2 version 9.0.0.2 from Creative Suit 5.5 on Windows 7
    Cheers

    Hi,
    Actually this error does not cause any harm except a presentation inconvenience. In my multi-select prompt I am using variable expression with dynamic repository variable. Dashboard results are correct. Just variable's value does not appear on page (error Error Codes: G689FFB3:SDKE4UTF
    Expression: @{biServer.variables['CUR_CAL_PER_MONTH_NAME']}). Pushing "GO" button on the prompt fixing the error but it's actually second execution of the dashboard.
    Any ideas ??

  • How do I add rows to a drop down list. I am using Excel 2008

    I am trying to incorporate added rows into a drop down list and am having no luch.  Any suggestions?

    Any of this help?
    Enter the items for your drop-down list into a list on the worksheet, one item per cell. In this example, I'll assume that the month names start in cell E1 and extend down to E12, but they can be in any out-of-the-way location on the worksheet. In Excel terminology, a rectangular group of cells (such as E1 to E12) is called a range.
    Select the cell that will contain the drop-down list. If you'd like more than one cell to display the same list, just select them all now rather than setting them up one at a time. (Click and drag to select a range; hold down Ctrl while you click to select non-adjacent cells.)
    Choose Data, Validation to display the Data Validation dialog box.
    Click the Settings tab.
    In the Allow field, select List.
    In the Source field, specify the range that contains the list items. In this example, the items are in cells E1 to E12, so type =E1:E12 into the field.
    http://support.microsoft.com/kb/141573
    NOTE   You cannot create a list in a shared workbook. You must remove the workbook from shared use first if you want to create a list.
    Every column in the list has AutoFilter enabled by default in the header row. AutoFilter allows you to filter or sort your data quickly.
    The dark blue border around the list clearly distinguishes the range of cells that makes up your list.
    The row that contains an asterisk is called the insert row. Typing information in this row will automatically add data to the list and expand the border of the list.
    A total row can be added to your list. When you click a cell within the total row, a drop-down list of aggregate functions becomes available.
    You can modify the size of your list by dragging the resize handle found on the bottom corner of the list border.
    http://office.microsoft.com/en-us/excel-help/about-excel-lists-HP001004433.aspx

  • How do I get the location bar drop-down list to show the most recently visited page at the top? I have no idea how it's deciding what to display.

    In IE when you show the drop-down list from the location bar, it show you all of your most recently visited pages in descending order with the most recent at the top. Firefox is showing me a list that I have no idea where it's getting the pages from or how it's ordering them. It doesn't update the pages or the order when I go to a new page. I have recently switched from IE to Firefox and cannot figure out how to get Firefox to do this; very annoying.

    That drop down list doesn't show recently visited pages, but shows list list of most visited sites sorted by what the Mozilla devs call frecency (frequency and recency) and is based on bonus points. It is not possible to have much influence on what shows on that list.
    If you want a list of recently visited sites then you can use a smart bookmark e.g. on the Bookmarks Toolbar with the location set to this smart folder.<br />
    Name: <b>Recently Visited</b><br />
    Location: <b>place:queryType=0&sort=4&maxResults=30</b><br />
    You need to close and restart Firefox to make that folder work as intended.
    * https://support.mozilla.org/kb/Smart+Bookmarks+folders
    See also:
    * http://developer.mozilla.org/en/The_Places_frecency_algorithm
    * http://kb.mozillazine.org/places.frecency.numVisits

  • How do I get a URL to display in the Awesome Bar drop down list? Some URL's appear in this drop down but I can't figure how they got there.

    There is a drop down list from the Awesome Bar containing some of my most frequently visited sites. How can I add URL's to this list?

    The location bar drop-down list shows items based on visited count (bonus points and frecency: frequency and recency) and if you have visited other URLs more often then those will replace other websites.
    *https://developer.mozilla.org/en/The_Places_frecency_algorithm
    You can't customize this drop-down list and you would have to bookmark websites to have easier access.

  • How to Pre-select Value in auto drop down list

    Hi,
    I have an automatically populated drop down list, and I'm trying to have it display with a pre-selected value (in the example 5). I didn't know where to start, so I modified the Dreamweaver code for "Set value equal to" from the Dynamic list function.The list displays, but the value defaults to 0. What am I missing?
    <?php
    echo '<select name="firstnumber" id="number">';
    for ($j=0; $j<11; $j+=1)
    echo  "<option value=\"$j\" <?php if (!(strcmp(\"$j\",5))) {echo \"selected=\"selected\"\";} ?>$j</option>\n";
    echo '</select>';
    ?>
    Thanks,
    Tim

    The problem is that you have nested PHP tags inside a PHP block. You can't do that. In fact, it's surprising that the code works at all. Normally, nesting PHP tags inside a PHP code block will trigger a syntax error.
    Also, your code is very difficult to read because of the way you use double quotes all the time. It's best to use single quotes for strings, except when you need to display the value of a variable inside a string. You can also nest double quotes inside a single-quoted string and vice versa, making for code that's much easier to read without all the backslashes.
    This is how I have rewritten your code:
    <select name="firstnumber" id="number">
    <?php
    for ($j=0; $j<11; $j+=1) {
      echo  "<option value='$j'";
      if (!(strcmp($j,5))) {
         echo 'selected="selected"';
      echo ">$j</option>\n";
    ?>
    </select>

  • How to show first parameter value in drop down list as a default value dynamically in ssrs report?

    Hi,
    in my ssrs report i have two parameters, accounts and Manager ,there is a cascading between the accounts parameter and manager parameter, as per the cascading we will get managers names based on the account we selected in the accounts parameter,
    my requirement is the first name in the mangers drop down list  has to get selected as default value.
    please help me with this, it is an urgent requirement.
    Thanks in advance,
    Naveen

    Hi NaveenMSBI,
    According to your description, you want to use cascading parameters in the report, if the accounts are selected when you preview the report, the first manager name will be selected from drop down list as the default value. If so, there can be two scenarios:
    • If manager is single-valued parameter, we can get Available Values and Default Values from the same query as below. Then when the accounts are selected, the first manager name will be selected as default value.
    SELECT managerName FROM table_name WHERE accounts IN (@accounts)
    • If manager is multi-valued parameter, we need to use different query for Available Values and Default Values. In this case, please refer to Patrick’s solution.
    For more information about Adding Cascading Parameters, please refer to the following document:
    http://technet.microsoft.com/en-us/library/aa337498(v=sql.105).aspx
    If you have any questions, please feel free to let me know.
    Best Regards,
    Wendy Fu

  • Need help using drop down list to calculate fields

    I am trying to use a drop down list to control how my field calculate. I have events packages that have multiple tiers. For example, Package One has (2) Tiers. Tier 1 costs $16 & Tier 2 costs $20. So based on the number of guests i want to be able to select the tier and it multiply and give me the total cost for the package. Ex: 2 Guests for Tier 1 = $32. Here is the code i have so far, it is placed under the change handler of the drop down list:
    var costPerGuest = 16;
    var tier = event.newText;
    if (tier == "Tier 1"){
      costPerGuest = 16;}
    else if (tier == "Tier 2"){
      costPerGuest = 20;}
    Total.rawValue = String(Guests.rawValue * costPerGuest)
    //Total.rawValue = DropDownList1.rawValue;
    What happens is when I run this it will not change unless the number of guests will change. So for the example above, if i switch it to Tier 2 after selecting Tier 1, it will not change my Total from $32 to $40.
    Any help would be greatly appreciated.

    Hi,
    I think ,you can use the event of EXIT event of dropdown list.
    var costPerGuest = 0;
    if (this.rawValue == "Tier1")
      costPerGuest = 16;
    else if (this.rawValue == "Tier2")
      costPerGuest = 20;
    else
    total.rawValue = Guests.rawValue * costPerGuest;
    Hope this helps,
    S,Candy.

  • Populating the data from table onto drop-down list.

    Hi all
    The following code i have used in trigger 'when-new-form-instance'
    DECLARE
    group_id RecordGroup;
    list_id Item := Find_Item('Lines.classification');
    status NUMBER;
    rg_name varchar2(10) := 'rgroup';
    BEGIN
    clear_list(list_id);
    group_id := Find_Group(rg_name);
    IF NOT id_null(group_id) then
    Delete_Group(group_id);
    End if;
    group_id := Create_Group_From_Query(rg_name,
    'select meaning from lookup_values where lookup_type='TC_CLASSIFICATION' and lookup_code in('BUSINESS','PERSONAL')');
    status := Populate_Group(rg_name);
    Populate_List(list_id, group_id);
    END;
    i have created a Record_Group from Object navigator(name:'rg_name').
    and used it in the above code.
    after this i try to run the form, i am not able to see the value which i drop-down list
    can any one suggest me abt this, and any changes i need to do in the property pallet,...
    Thanks
    Raj

    u3 wrote:
    No, Populate_List requires that the record group is created at runtime.Actually you're wrong ;)
    POPULATE_LIST works with both, record groups created at runtime AND at design time.
    Try the below code on SCOTT schema with a list item and a button trigger:
    Record Group created at design time
    DECLARE
         RG_NAME VARCHAR2(10) := 'RGROUP';
         V_DUMMY NUMBER;
    BEGIN
         CLEAR_LIST('LIST_ITEM1');
         V_DUMMY := POPULATE_GROUP(RG_NAME);
         IF V_DUMMY = 0 THEN
              CLEAR_LIST('LIST_ITEM1');
              POPULATE_LIST('LIST_ITEM1', RG_NAME);
         END IF;     
    END;
    Record group Created at Runtime
    DECLARE
         GROUP_ID RECORDGROUP;
         RG_NAME VARCHAR2(10) := 'RGROUP';
         QUERY_TEXT VARCHAR2(1000) := 'SELECT ENAME, TO_CHAR(EMPNO) FROM EMP';
         V_DUMMY NUMBER;
    BEGIN
         CLEAR_LIST('LIST_ITEM1');
         GROUP_ID := FIND_GROUP(RG_NAME);
         IF NOT ID_NULL(GROUP_ID) THEN
              DELETE_GROUP(GROUP_ID);
         END IF;
         GROUP_ID := CREATE_GROUP_FROM_QUERY(RG_NAME, QUERY_TEXT);
         CLEAR_LIST('LIST_ITEM1');
         V_DUMMY := POPULATE_GROUP(RG_NAME);
         IF V_DUMMY = 0 THEN
              CLEAR_LIST('LIST_ITEM1');
              POPULATE_LIST('LIST_ITEM1', RG_NAME);
         END IF;     
    END;It does work with me both ways, I suggest you test it.
    Tony

  • How to make default value in a drop down list

    Hi,
          I have created a drop down list using Selection-Screen code. I have three values in it. I would like to make one of the option as a default value. How to achieve it?
    I am working on module pool program. I have few screens as a part of my program. I have created print button on tool bar of one screen but that print button is appearing on the other screens too. How to avoid it?
    Help would be appreciated...
    Thanks
    Edited by: mohammed ibrahim on Oct 10, 2008 8:43 PM

    1) let drop down box be g_dd.
      if g_dd is initial.
      g_dd = option2.
      endif.
    2)
    by default same pf-status is used by all the screens in the same program
    if sy-dynnr = 'screen_no'. " for screens for which you do not want button to come
    set pf-status 'abc' excluding 'fcode_of_button'
    endif.
    or
    data: git_fcode type sy-ucomm with header line.
    git_fcode = 'fcode_of_button'.
    append git_fcode.
    if sy-dynnr = 'screen_no'. " for screens for which you do not want button to come
    set pf-status excluding git_fcode
    endif.
    Edited by: Amit Gupta on Oct 11, 2008 11:36 AM

Maybe you are looking for

  • TV as wireless display

    I need to connect my Powerbook wirelessly to use my TV as an occasional alternate display. What are my options?

  • How do I retrieve elements in a xml document ?

    I would like to know how to retrieve elements from xml document ? I have created a document already, but how do I proceed from there ? Also, how do I access the values inside, the attributes and value ? Thank you.

  • Satellite Pro A200-1NB - Can I use Windows 7 64bit?

    This is my laptop: Satellite Pro A200-1NB Part Number : PSAE7E-00V00CG3 http://eu.computers.toshiba-europe.com/innovation/jsp/autoDetect.do?service=EU&ACTION=PROCESS_DETECTION& TYPE=FORWARD&SOURCE=SMP&COUNTRY=&QSA=TRUE&MODEL=Sa tellite+Pro+A200&SERIA

  • Folder size is twice that of its contents????

    Startup Disk > Users > Username My Username folder shows a folder size that is just about double the size of all of its visible folders.  I can see this when viewed in the Finder in List View with Folder Size Shown as my default View setting.    Any

  • Browser Message

    I received a browser message today from Rogers AT&T for a promotion they are running but do not know how to view it. I have the browser icon with a 1 at the top of my screen where it would should text and email messages to let me know I have a new me