Loading combo box from oracle

Loading combo box from oracle

how can i load values into a combobox from oracle database when a value is selected in another combo box?

View Answers

February 4, 2011 at 3:31 PM

Hi Friend,

We are using Mysql database.

Try this:

1)country.jsp:

 <%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showState(str){
      if (typeof XMLHttpRequest != "undefined"){
      xmlHttp= new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlHttp==null){
      alert("Browser does not support XMLHTTP Request")
      return;
      } 
      var url="state.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("state").innerHTML=xmlHttp.responseText   
      }   
      }
      </script>  
      </head>  
      <body>  
      <select name='country' onchange="showState(this.value)">  
       <option value="none">Select</option>  
    <%
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from country");
 while(rs.next()){
     %>
      <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
      <%
 }
     %>
      </select>  
      <br>  
      <div id='state'>  
      <select name='state' >  
      <option value='-1'></option>  
      </select>  
      </div>  
      </body> 
      </html>

2)state.jsp:

<%@page import="java.sql.*"%>
<%
String country=request.getParameter("count");  
 String buffer="<select name='state' ><option value='-1'>Select</option>";  
 try{
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from state where countryid='"+country+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(3)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }

 %>

For the above code, you need to create 2 database tables.

1)country

CREATE TABLE `country` (                                 
           `countryid` bigint(255) NOT NULL auto_increment,       
           `countryname` varchar(255) default NULL,               
           PRIMARY KEY  (`countryid`)                             
         )

2)state

CREATE TABLE `state` (                                   
          `stateid` bigint(255) NOT NULL auto_increment,         
          `countryid` int(255) default NULL,                     
          `state` varchar(255) default NULL,                     
          PRIMARY KEY  (`stateid`)                               
        )

Thanks


February 7, 2011 at 10:12 AM

Thank you for your answer.


February 7, 2011 at 4:13 PM

How could I get the selected value from the combobox in the same page? I coudn't use request.getParameter(), because i need the second combo box in the same page.









Related Tutorials/Questions & Answers:
Loading combo box from oracle
Loading combo box from oracle  how can i load values into a combobox from oracle database when a value is selected in another combo box
loading value into combo box by selecting value from other combo box - JSP-Servlet
loading value into combo box by selecting value from other combo box  ... is that as i select state from state_combo_box,then the next combo box is dynamically... box with constituency corresponding to district..... all three combo box
Advertisements
retrieving from oracle database using jsp combo box
retrieving from oracle database using jsp combo box  hi this is my code in this once i select the server type and version of the server the process name of the server has to display in the process name field from the oracle
Retrieving Data from Database to fill Combo Box
Retrieving Data from Database to fill Combo Box  Sir, I have a JSP Page with a combo box and a label. I have a database that has two fields id and an image. Now I want to fill the combo box with image and on selecting
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
Dynamic loading of Combo box list using servlet - JSP-Servlet
Dynamic loading of Combo box list using servlet  I have the category and their sub categories in database. How can I load the sub category from... I give theortical descrption read it! Select a value from drop dwon box
Populate a combo box using data from a database
Populate a combo box using data from a database  Hi Guys, In need... combo box which will then load the next combo box values, now i know how... to the client using ajax, and then populate the combo box, I must'nt reload
how can retrive value from combo box in servlet?
how can retrive value from combo box in servlet?  i have a jsp page with combobox. And i want to get value from combox to servlet
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking the value of combo box . I am not getting it plz help me out .   hi
Retrieving data from data base using jsp combo box
Retrieving data from data base using jsp combo box  Hi guys please... combo box is there and another filed is version of the server(like 1.0,2.0) like... of the server it has to display the process name from database into the process name
Acees data from database using combo box - JSP-Servlet
Acees data from database using combo box  please let me how i access the data from database when i select combo box combo2 having values Arts, Commerce, Science. this combo box will appear when first combo box class_name having
combo box
combo box  Hi, [_|] dropdown box... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get usernames from the database & upon selection of particular user i should get
How to get the values from the Combo Box - JSP-Servlet
How to get the values from the Combo Box   Sir, Actually i am getting the values in the combo box from table.I want what ever... in their respective text box. e.g suppose i select ram values from the combo box and its
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
Combo Box operation in Java Swing
, remove items from the combo box. This program shows a text field, a combo box... at the 0th (zero) position of the combo box will be remove from the combo box... Combo Box operation in Java Swing   
date in combo box
date in combo box  strong texthello, how can i desplay the current year and next year in combo box???!!! it must be uppdate atumaticaly every year>>>
assigning arraylist to combo box
assigning arraylist to combo box  Hi I am busy coding the Airline Reservation program, i have an arraylist of locations which i want to assing to the combo box. please help
combo box connection
combo box connection  how to provide connection between three combo boxes,if my 1st combo box is course and 2nd combo box is semester and 3rd combo box is my subjects.what's the coding to provide the connection between this three
Uninstall Oracle Virtual Box
Uninstall Oracle Virtual Box  Hi, Is there any video of uninstalling Oracle Virtual Box? Thanks
how i conditional access the data from database using combo box. - JSP-Servlet
how i conditional access the data from database using combo box.   i have combox box named class when i select its value 11 or 12, another combo box... access the data from database when i select class 11 0r 12. Here is JSP file
Combo Box - Struts
Combo Box  I hava acombo box cnnected to my database via html collections. When selecting an option, i want to display specific parts (sectons) on my web page....am trying to use logic:present and logic:empty but its not working
populating the combo box - Struts
populating the combo box  Hi I am having problem populating the combo box with a table in MS SQL Server 2005 Management Studio Express. Belo is the extract from the Struct?jsp application. Sector
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page... = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from country
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page import... = stmt.executeQuery("Select * from country"); while(rs.next()){ %>
Problem With Combo Box Editable Property
Problem With Combo Box Editable Property  Hi I am new To Flex i had set Combo Box Editable Property as true. But I didn't get the property filtering in the combo box like when you enter text "S" in the combo box then the names
Helps with combo box and frame
Helps with combo box and frame  Hi i have a combobox and when i click... on the second window and click confirm i would have the information on the combo box. i... combo; JTextField txtBox; private String PersonViewing; private String
Dojo Combo Box
Dojo Combo Box          In this section, you will learn what is combo box and how to create a combo box in dojo. For creating the Combo box  you need "
combo box - JSP-Servlet
combo box  I am using a JSP form in which a combobox is given and I want to populate data in it from database and on the basis of yhe selected item I want to display related data in a textbox  Hi Friend, Create
java combo box
java combo box  how to display messagedialogbox when the combobox is null, Thanks in advance
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to retrieve data from database by using combo box value in jsp?  Hello friend i want use only one jsp page.. but u give 2 pages... I want to work in one page... Pl response.. I do not need getParameter... Pl respose me
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only...("Select * from country"); while(rs.next()){ %> <option value="<
JavaScript Dynamic Combo Box
in respective arrays. As the user selects a country from the first combo box, the cities...JavaScript Dynamic Combo Box Here we are going to create dynamic combo box...: On selecting the value from the first combo, related values
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from... box in javascript when elements retrieving from database.. That is whenever I insert new course in a table.. It should be seen in my list box..ADS
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
How to create Combo Box in SWT
is called. If you select the cold drink from the first combo box, the array of drinks... How to create Combo Box in SWT       This section illustrates you how to create a combo box
Combo box value Error - WebSevices
Combo box value Error   if($_SERVER['REQUEST_METHOD'] == 'POST' ) { $visa =trim($_POST['hdVisa']); } document.frmProposal.hdVisa.value = document.getElementById('cmbVisa').value; Error
how to create a combo box in html
how to create a combo box in html  <tr> <td>Number<span class=mandatory>*</span></td> <td> <select name="number" id="course" style="width:158px;"> <option value="none">----Select
How to retrieve data by using combo box value in jsp? - JSP-Servlet
... i already stored combo box values from database. pl...How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box
Sql query from oracle
Sql query from oracle  Please help me that I want to get the table names form the existing database who does it having eid coloumn plz provide me query in oracle database
how to get combo box value - JSP-Servlet
how to get combo box value  i have created 1 servlet & 1 jsp page. in servlet page i have fired query & fetched name & its id & that i have shown in combo box in jsp page: (small part of my code) "> now i want
JavaScript Combo Box Validation
JavaScript Combo Box Validation       This application illustrates how to validate the combo box using JavaScript validation. In this example we create a combo box of different
Sub combo box problem - Development process
Sub combo box problem  Hi, In this code Sub-Combo box is not working. plz solve the problem Search Page var arr = new Array(); arr["Select"] = new Array("-select-"); arr["Dkn/Tmz"] = new Array
com.vaadin - vaadin-combo-box-flow version 2.1.3 Maven dependency. How to use vaadin-combo-box-flow version 2.1.3 in pom.xml?
com.vaadin  - Version 2.1.3 of vaadin-combo-box-flow Maven dependency? How to use  com.vaadin  - Version 2.1.3 of vaadin-combo-box-flow in pom.xml? How to use vaadin-combo-box-flow version 2.1.3 in pom.xml? Learn to use
com.vaadin - vaadin-combo-box-flow version 1.0.7 Maven dependency. How to use vaadin-combo-box-flow version 1.0.7 in pom.xml?
com.vaadin  - Version 1.0.7 of vaadin-combo-box-flow Maven dependency? How to use  com.vaadin  - Version 1.0.7 of vaadin-combo-box-flow in pom.xml? How to use vaadin-combo-box-flow version 1.0.7 in pom.xml? Learn to use
com.vaadin - vaadin-combo-box-flow version 3.0.2 Maven dependency. How to use vaadin-combo-box-flow version 3.0.2 in pom.xml?
com.vaadin  - Version 3.0.2 of vaadin-combo-box-flow Maven dependency? How to use  com.vaadin  - Version 3.0.2 of vaadin-combo-box-flow in pom.xml? How to use vaadin-combo-box-flow version 3.0.2 in pom.xml? Learn to use

Ads