Populate the JSP's select box from database on jsp load

hai all,
can any one help me in knowing how to populate the select box of a jsp
with data from the database?
thanks and regards,
ravikiran

<%
String sQuery = "select id,Name from tablename";
rs = stmt.executeQuery(sQuery);
%>
<select name="sltName">
<%
while(rs.next()){
String sId = rs.getString(1);
String sName = rs.getString(2);
%>
<option value="<%=sId %>" > <%=sName %> </option>
<%
%>
</select>

Similar Messages

  • How to populate the dropdown in selection widget from a file?

    i am using a cq:widget of xtype selection and type select. I got lot of values as my options.i want a simple procedure to populate them. They have mentioned that they can be populated from a json response. Can you explain how to do the same? or is ther any other method for the same

    Steve,
    You can check OOTB List component at below location.
    /libs/foundation/components/list/dialog/items/list/items/displayAs
    Here dispalyAs tab having cq:widget of xtype selection in which values are populating through displayoptions.json.jsp which is referenced by options property set on displayAs tab.
    Regards
    Briejsh Yadav.

  • How do I stop the "Confirm Dialog Preference" box from appearing everytime I load a page?!

    Every time I a go to a new page, whether it is the same site or not, I get a dialog box that appears that reads "Confirm Dialog Preference," and the options include yes or no. How do I get this to stop? It is really, really annoying.

    Can you attach a screenshot showing the dialog?
    Does the issue still occur if you start Firefox in Safe Mode? http://support.mozilla.com/en-US/kb/Safe+Mode
    How about with a new, empty profile? http://support.mozilla.com/en-US/kb/Basic%20Troubleshooting#w_8-make-a-new-profile

  • 3 cfgrids on one page.  Columns from grid 1,2 and 3 are swapping the first select box from each grid.

    ColdFusion 11, hot fix 3 installed but did not help. There are no binds.
    This one has been driving me crazy and I have finally figured out that it is the first column in each grid where there is a select box via "valuesdisplay" that is the issue. Select box results are switching grids!
    Example of how it is coded to display:
    Grid 1 - gridcolumn should have a dropdown with 1,2,3
    Grid 2 - gridcolumn should have a dropdown with a,b,c
    Grid 3 - gridcolumn should have a dropdown with x,y,z
    However, the results in the dropdowns in the grids are:
    Grid 1 - x,y,z (should be 1,2,3)
    Grid 2 - 1,2,3 (should be a,b,c)
    Grid 3 - a,b,c (should be x,y,z)
    This only happens with the first dropdown for each grid. Any other columns with dropdowns do not have any issues and do not swap out to the wrong grid.
    Sample of my code from the grids:
    Grid 1:
    <cfgrid name = "evalgrid"
      height="200"
      autowidth="no"
      font="arial" fontsize="12"
      query = "getevalfinal"
      SORT="Yes"
      selectmode="edit"
      format="html"
      insert="yes"
      delete = "#deletevalue#">
      <CFGRIDCOLUMN NAME="numberofschools" HEADER="numberofschools"
      HEADERALIGN="LEFT" DATAALIGN="LEFT"
      BOLD="Yes" ITALIC="No"
      SELECT="Yes" DISPLAY="Yes"
      HEADERBOLD="Yes" HEADERITALIC="No"
      VALUES = " ,NA,1,2,D"
      VALUESdisplay = "Blank,NA,1,2,D" valuesDelimiter=","
      width=50>
    </cfgrid>
    Second Grid:'
    <cfgrid name = "SecondGrid"
      height="100" width="700"
      font="arial" fontsize="12"
      query = "getsecurity"
      SORT="Yes"
      selectmode="edit"
      format="html"
      insert="yes"
      delete = "#deletevalue#"
      autowidth="yes"
      >
      <CFGRIDCOLUMN NAME="userrole" HEADER="userrole"
      HEADERALIGN="LEFT" DATAALIGN="LEFT"
      BOLD="Yes" ITALIC="No"
      SELECT="Yes" DISPLAY="Yes"
      HEADERBOLD="YES" HEADERITALIC="No"
      VALUES = "#olduserrole#"
      VALUESdisplay = "#olduserrole#" valuesDelimiter=","
      WIDTH=300
      font="arial" fontsize="12">
    </cfgrid>
    In the above code, userrole values end up being in the wrong grid where numberofschools values should be and vice versa.
    Appreciate any help!
    B.

    You may find this article useful: [http://balusc.blogspot.com/2007/10/populate-child-menus.html].

  • Select data from DataBase

    Hi;
    I try to select data from DataBase, But I get the following error, Could anyone help? thanks.
    Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.driver.
    OracleDriver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at Lookup.main(Lookup.java:12)
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class Lookup {
        public static void main(String[] args)
            throws SQLException, ClassNotFoundException {
            String dbUrl = "jdbc:oracle:thin:@augur.scms.waikato.ac.nz:1521:comp319";
            String user = "group029";
            String password = "group029";
            // Load the driver (registers itself)
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection c = DriverManager.getConnection(dbUrl, user, password);
            Statement s = c.createStatement();
            //SQL code:
            ResultSet r =
                s.executeQuery("SELECT * " +"FROM movie");
         StringBuffer results= new StringBuffer();
            ResultSetMetaData metaData = r.getMetaData();
         int numberOfColumns = metaData.getColumnCount();
         for(int i=1; i<=numberOfColumns; i++)
             results.append(metaData.getColumnName(i)+"\t");
         results.append("\n");
         while (r.next()){
             for( int i=1; i <=numberOfColumns; i++)
              results.append(r.getObject(i)+"\t");
             results.append("\n");
         s.close();
    }

    It's a classpath problem. Either you mistyped the class name, or you don't have the class in your classpath. I think Oracle's drivers come in db12.zip or db12.jar or some such. Whatever that jar or zip file is, it has to be in your classpath, but it's not.
    Or it is in your classpath, but you're in an appserver context where the classloader that the container provides for your app uses something other than the classpath variable. For instance, in tomcat, the jar file would be uder webapps/yourApplication/WEB-INF/lib I think.

  • How to select rows from database like 10 to 20 etc

    Hi Experts,
    I want to select rows from database like row number 10 to row number 20.How could it be done?

    HI,
       First get the data into the INTERNAL TABLE from the FLAT FILE and read the internal table using the index.
        ex: 1) Read table ITAB index 10.
              2) Read table ITAB index 20.
    or use as said by  Srinivas Gurram, to get the range of records using where condition to the loop.
    <REMOVED BY MODERATOR>
    Edited by: Ravi Kumar on Jun 9, 2008 4:01 PM
    Edited by: Alvaro Tejada Galindo on Jun 9, 2008 3:16 PM

  • What is the defference between select single * from and select * from Where

    What is the defference between select single * from and select * from Where
    which is prefferable and best one.

    Hai,
    *Difference Between Select Single and Select * from table UpTo One Rows:*
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly:  to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

  • How to get the values of Select-options from the screen.

    The value of parameter can be obtained by function module 'DYNP_VALUES_READ' but How to get the values of Select-options from the screen? I want the F4 help values of select-options B depending on the values in Select-option A.So I want to read the Select-option A's value.

    Hi,
    Refer this following code..this will solve your problem...
    "Following code reads value entered in s_po select options and willprovide search
    "help for s_item depending upon s_po value.
    REPORT TEST.
    TABLES : ekpo.
    DATA: BEGIN OF itab OCCURS 0,
    ebelp LIKE ekpo-ebelp,
    END OF itab.
    SELECT-OPTIONS   s_po FOR ekpo-ebeln.
    SELECT-OPTIONS s_item FOR ekpo-ebelp.
    INITIALIZATION.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_item-low.
      DATA:
      dyn_field TYPE dynpread,
      temp_fields TYPE TABLE OF dynpread,
      zlv_dynpro TYPE syst-repid.
      zlv_dynpro = syst-repid.
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname     = zlv_dynpro
          dynumb     = syst-dynnr
          request    = 'A'
        TABLES
          dynpfields = temp_fields
        EXCEPTIONS
          OTHERS     = 0.
      LOOP AT temp_fields INTO dyn_field.
        IF dyn_field-fieldname EQ 'S_PO-LOW'.
            SELECT * INTO CORRESPONDING fields OF TABLE itab FROM ekpo
            WHERE ebeln EQ dyn_field-fieldvalue.
            EXIT.
        ENDIF.
      ENDLOOP.

  • I can open a new browser window, but not a new tab, neither by clicking the plus or selecting it from the menu. I have fully updated firefox and also restarted. what's going on?

    I can open a new browser window, but not a new tab, neither by clicking the plus or selecting it from the menu. I have fully updated firefox and also restarted. what's going on?

    I have the same problem with the right click and do not have the ask toolbar installed on my system?

  • Hi All, I have new iphone 4s and want to import my contacts from my old Orange SIM (the contacts have all been copied to SIM). I enter the SIM and select "Import from SIM" in the settings -- Calendar, Contacts etc it look like Ok but nothing copied,helpp

    Hi All, I have new iphone 4s and want to import my contacts from my old Orange SIM (the contacts have all been copied to SIM). I enter the SIM and select "Import from SIM" in the settings --> Calendar, Contacts etc it looks like Ok but nothing copied,I tried hundreds of time and waited 2 day but still nothing and I again made sure that I do have the Contacts in the Microsim and it is there but cant import? dunno why???

    I have never used it, but have heard good things...
    http://www.littlemachines.com/

  • Help needed: clarifying the use of beans to pass data from database to JSP

    Hi everyone,
    I am sure you all get fed up with being asked this question as I can see it is asked a lot when googled, but the answers given have not cleared things up for me.
    Anyway, I have a JSP page that contains a text box, submit button and a select box of size 10. The user enters a search string and the form submits the data and reloads the same page. From the code you can see the Name property of the bean is set.
    <jsp:useBean id="vtm" class="FinalYearProject.Types.VtmType" scope="page" />
    <jsp:setProperty name="vtm" property="NM" value="${param.NM}" />I then need to be able to use that name to query a postgresql database. I have a JDBCConnector class with the method:
        public ResultSet searchTable(String NM ) throws SQLException {
            String[] names = NM.split(" ");
            NM = "";
            for(int i = 0; i < names.length; i++) {
                NM = names[i] + "%";
            return stat.executeQuery("SELECT * FROM vtm WHERE nm ILIKE '" + NM + "';");
        }This method however can be changed.
    My question really is what is the best way for me to take the name, get the resultset and pass back the VtmType objects to the jsp so that I can populate my select box, and where should each part be handled i.e. the JSP page, the VtmType, the JDBCConnector.
    I may be going about it completely the wrong way and using beans incorrectly, but I just cant seem to get my head around the problem.
    Any help would be much appreciated,
    Thanks.

    Hi,
    Thanks for the help, I actually found some literature about the JSP Model 2 and realised that was what I needed to do. I have now re-written everything and it has made my life a lot eaiser, typically this was before I checked back on this post though!
    Anyway, I now have JSP pages requesting Servlets which create beans and call classes that access the database. The servlet then forwards the beans and where necessary a small of html to another JSP. Like you have suggested.
    One problem I have now however, is that the user needs to be logged in to access some of the pages. An error page with the correct message is displayed to the user when it is processed via the servlet.
    //Servlet detects an error
    request.setAttribute("errorMsg", "1");
    gotoPage("/loginError.jsp", request, response);
    //JSP detects which errorMsg to display
    <c:set var="errorMsg" value="${requestScope.errorMsg}" />However, when the user does not sign in and clicks a link which is blocked the JSP forwards directly to the error JSP.
    //Tests to see if user is logged in
    <c:if test="${empty user.username}">
        <jsp:forward page="/loginError.jsp">
            <jsp:param name="errorMsg" value="3" />
        </jsp:forward>
    </c:if>The problem with this is that the only way I can see of checking the errorMsg type is with:
    //JSP checks which errorMsg to display
    <c:set var="errorMsg" value="${param.errorMsg}" />Which is different to how I determine the errorMsg from the Servlet. Is there a way of getting the errorMsg type that is the same for both actions?
    Thanks.

  • Populate two additional select boxes from main box...

    hey all -
    i am new at most of this, so please bare with me.
    I am trying to go from one box to the next (twice over), and am having difficulty getting to the third box.
    I have the original box "select1" and it populates "select two" just fine, but i do not have the third population....looking for help in getting a third box.
    I would like box one to populate box two, from the selection in box two, i would like to populate box three, and have that as a selection as well.
    here is what i have so far...
    <script>
    function dropDownChanged(dd)
         if(eval('typeof(' + dd.name.replace(/:/g, "_") + '_children) == \'undefined\'')) return;
         var thisDd;
         if(document.all)
              thisDd = document.all[eval(dd.name.replace(/:/g, "_") + '_childcontrol')];
         else
              thisDd = document.getElementById(eval(dd.name.replace(/:/g, "_") + '_childcontrol'));
         thisDd.options.length = 0;
         var childElements = eval(dd.name.replace(/:/g, "_") + '_children');
         for(var c=0 ; c < childElements.length ; c+=2)
              if(childElements[c] == dd.value)
                   for(var o=0 ; o < childElements[c+1].length ; o+=2)
                        thisDd.options[o/2] = new Option(childElements[c+1][o], childElements[c+1][o+1]);
         dropDownChanged(thisDd);
    </script>
    <script>var opp_childcontrol = 'opp';
    var opp_children = ['no',['------------Select first--------------------','no'],'Coffee Businesses',
    ['selction1','selection1'],'Direct Marketing',['selection2','selection2'],'Employment & Personnel',['selection3','selection3'],'Food-Related Businesses',['selection4','selection4','selection5','selection5','selection6','selection6'],'Printing Businesses',['selection7','selection7'],
    'Senior Care',['selection8','selection8']];
    </script>after the first box is selected, the second box populates great, now i am wanted the "selection1 - selection 8" to populate a third box with information determined by the second selection, that is also a selection that can be chosen by the end user....
    all of this information is sent via web form to a crm...
    can you help me to create this third dropdown list with the ability to select an option from there?
    I would greatly appreciate any and all help you can provide!
    ray

    that sounds good to me....but again, i am not the expert at this by any means...I am going off of what has been given to me in the first script.
    can you assist?
    thanks,
    ray

  • How to Populate values dynamically in Select Box.

    Hi All,
    I have few select boxes in my webdynpro application. Right now I am populating them using Harcoded values in the Dictionary. But I dont want to harcode the values in the dictionary, i want pull the values from database tables or  text files of EP KM. Just let me know which is the better way to populate the select box without hardcoding & why ?
    Thanks in Advance.
    Regards,
    Aditya Metukul

    Hi Aditya,
    Getting values from KM and database is possible
    It depends on your requirement
    ie if the dropdown should contain details of documents from KM or it should display the details in a table
    if it is oracle table see this link
    Webdynpro and Oracle
    if you want to get data from km see this tutorial
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tutorial on using knowledge management functions in web dynpro - 26.htm
    Hope this helps you
    Regards
    Rohit
    Regards
    Rohit

  • How to gather option values from database in jsp

    jsp experts
    my problem is that i have to populate the optional values that user has to selecet his choice .
    we could have done it by :
    <optional value="item1">item1
    <optional value="item2">item2
    </select>
    but in our database if new category of item is enlisted then what ??? ,thats why we go for populating the values from fetching from database by simple class & populate values in the optional values.
    can any one help about it

    Hi Avina,
    You need to invoke a method from your jsp file which interacts with the database. If you are following the MVC pattern which segregates the View and Contoller part, invoke the controller jsp from your View using the include tag.
    Say this is the View.jsp
    // all your initial page include statements --
    <%
    // all your java code (if necessary)
    %>
    <jsp:include page="Controller.jsp" >
    <jsp:param name="command" value="getOptionList"/>
    </jsp:include>
    <!-- all your html tags -->
    // If you are following my technique, there should be a Controller.jsp which interacts with your database thru some class which you instantiate in this jsp, which invokes some method (that is why i have passed a parameter, so that if u want to make a check you can do so - u may or may not pass the parameters - based on ur requirements).
    Code in Controller.jsp:
    <%
    // MyClass is the class which does the querying into the database.
    // obj.getOptions() is a method in that class which returns a Vector
    // containing all the options from your database.
    // Please ensure that you import the package in this jsp file, so as
    // to get the MyClass.class in this jsp.
    String getWhat = request.getParameter("command");
    if ( getWhat != null && getWhat.equalsIgnoreCase("command") ) {
    MyClass obj = new MyClass();
    java.util.Vector optionsAvailable = obj.getOptions();
    session.setAttribute("Options", optionsAvailable);
    %>
    -------------- End of Controller.jsp related work ---------------
    // Returning back to the code in the View.jsp:
    Once the including is over, the control will return to the next line of code in View.jsp. Just retrieve the data from the session:
    Continued - View.jsp
    <select name="itemsInDB">
    <option value="Select"> Select </option>
    <%
    /* Now you have a vector containing all the options from
    your database. */
    java.util.Vector vecOptions = (java.util.Vector)
    session.getAttribute("Options");
    for (int i=0; i<vecOptions.size(); i++) {
    %>
    <option value="<%=vecOptions.elementAt(i)%>"><%=vecOptions.elementAt(i)%></option>
    <%
    %>
    </select>
    Well thats all thats required. Your problem is solved. You will get a list of all the options in your database. Happy Coding

  • Help with building a select box from a query?

    New thread from a topic I started yesterday. From the responses, and a search of other threads, I realized that I was way off base:-) So, I went back and verified that my TomCat setup was alright. After a few tweeks I verified that I could display the index page and successfully run all of the example servlets and jsps. I then built a simple login.jsp and an associated bean to verify a user id and password on an ldap db. That works good. Next, I built a bean which runs a query against the same ldap db and returns a list of last names. What I want to do is use the last names in the bean to populate my select box. At first I was trying to build the html with the list from my bean, i quickly realized you guys didn't like that approach. So, can someone explain, in some detail (because I'm really dense), just how I can return the values from my bean and build a select box with those values.
    regards,
    Mat
    BTW Gone to see Lord of The Rings...back in about 5 hours :-)

    Just in general, I prefer knowing how to do things the "old-fashioned way" first before using other tools, because if it comes time for you to take over someone else's code, you'll probably find that they did it the old way and you'll want to understand that. Further, the new ways are based on the old ways for many things.
    Struts is a good system, but unless you have some understanding of the basics, it's probably going to be harder to understand it. If you have the time, I'd say at least go thru one book on JSP/servlets (which should be all about the basics, maybe a slightly older book) and go thru the examples in it.

Maybe you are looking for

  • Gallery picture id's

    In my gallery on my tablet I want to be able to rename groups of pictures. So far I cannot find out how to do this.

  • Weather in iOS 7 Notification Center flashes and disappears

    This is weird. Upgraed to iOS 7 on lauch and the weather description in notification center quickly flashes then is gone. The weather description as text only is instead of the the graphical widget, in my opinion, is far less usable than it used to b

  • Do I need to keep my xmp files after converting my raw files to dng?

    I originally set up Lr to automatically build xmp files.  Recently, I decided to go with dng files and have converted all my raw files to dng.  Can I now delete all my xmp files and change my Lr setting so xmp files are no longer automatically produc

  • Weblogic in running state. no health check status (empty)

    Hello. I have installed weblogic 10.3.5 with os unix in the production enviromente. The managed servers fail with the no health status, this behavior is ramdon and the workaround is restart the managed servers. Do you know how to solve this problem?

  • When creating new Timecard, our user couldn't select Project from the popup

    Hey Guys, Thanks for your attention, I need help. One of our user could not create new Timecard with IE9, because when she selected new project she met the error as below, Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows N