Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to add data dynamically from database into a dropdown list in a jsp

Have Programming Question? Ask it here!
 
 
 


science student
how to add data dynamically from database into a dropdown list in a jsp
4 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners


hi friends i am doing a project in jsp and oracle as my database.In my project i have an registration form containing many text fields.there is no problem in storing them into the database,this registration form contains name and department fields also.I have a create an jsp page in which there should 2 drop down list.In that first list is for department and the 2nd list for the names of the persons who work in that department.The values into the drop down list should get dynamically from the database and whenever a new person has registered his name should also be included in the list dynamically and any updating on the department i.e if the person department has been changed he should come under his new department list. Please could any one send the exact code which can solve my problem. Please try to send so soon as possible Thank you in advance


Advertisement
View Answers

May 18, 2011 at 1:00 PM


1)selDept.jsp:

 <%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showEmp(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="selEmp.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("emp").innerHTML=xmlHttp.responseText   
      }   
      }
      </script>  
      </head>  
      <body>  
      <select name='dept' onchange="showEmp(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 dept");
 while(rs.next()){
     %>
      <option value="<%=rs.getString("DEPT_NO")%>"><%=rs.getString("DEPT_NAME")%></option>  
      <%
 }
     %>
      </select>  
      <br>  
      <div id='emp'>  
      <select name='emp' >  
      <option value='-1'></option>  
      </select>  
      </div>  
      </body> 
      </html>

2)selEmp.jsp:

<%@page import="java.sql.*"%>
<%
String no=request.getParameter("count");  
 String buffer="<select name='emp' ><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 emp where DEPT_NO='"+no+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString("EMP_NAME")+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>


May 18, 2011 at 1:02 PM


For the above code, we have used two database tables:

1)dept:

CREATE TABLE `dept` (                     
          `DEPT_NO` int(100) default NULL,        
          `DEPT_NAME` varchar(255) default NULL   
        );

2)emp:

CREATE TABLE `emp` (                                      
          `EMP_NO` int(10) NOT NULL auto_increment,               
          `EMP_NAME` varchar(100) default NULL,                   
          `DESIGNATION` varchar(100) default NULL,                
          `JOINING_DATE` date default NULL,                       
          `SALARY` int(100) default NULL,                         
          `DEPT_NO` int(100) default NULL,                        
          `DEPT_NAME` varchar(100) default NULL,                  
          PRIMARY KEY  (`EMP_NO`)                                 
        );


May 18, 2011 at 6:47 PM


thank u for the code.But i did not get the result.If you don't mind could display whats the output for this code. If possible please send another code which uses oracle as its database i don't know mysql.send an example that has the registration form and full working which is similar to my question. Thank you in advance



March 9, 2012 at 3:31 PM


hi friends i am doing a project in jsp and mysql as my database.In my project i have an edit form containing many text fields.there is no problem in storing them into the database,this registration form contains date,flight number,origin and departure fields also.I have a create an jsp page in which there should multiple drop down list.In that first list is for flight number and the 2nd list dependent on 1st list and subsequently.The values into the drop down list should get dynamically from the database. Please could any one send the exact code which can solve my problem. Please try to send so soon as possible Thank you in advance



Related Tutorials/Questions & Answers:
how to add data dynamically from database into a dropdown list in a jsp
how to add data dynamically from database into a dropdown list in a jsp ... get dynamically from the database and whenever a new person has registered his name should also be included in the list dynamically and any updating
JSP Get Data Into Dropdown list From Database
JSP Get Data Into Dropdown list From Database In this section we will discuss about how to fetch data dynamically into the dropdown list in JSP... data from the database and set it into the dropdown list in JSP using MySQL
Advertisements
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
how to retreive data dynamically from mysql to drop down list
how to retreive data dynamically from mysql to drop down list   sir... fron end using jsp , after storing the data successfully .i want to retrieve the data of a particular column in a table into drop down list dynamically
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only dynamically added text field but want code to retrive value of dynamically
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class... respective to that class from database. please help by providing the code in jsp
How to add a DropDown List in Flex DataGrid
How to add a DropDown List in Flex DataGrid  hi I am trying to add a DropDownList in a DataGrid table. After the user selects one of the items from... select from one of the choices in the list. That's my reason for trying to add
How to access Contacts from gmail using LDAP in JSP dropdown list
How to access Contacts from gmail using LDAP in JSP dropdown list  HI, I am creating a JSP page in which i have to make a dropdown box, and access gmail contacts in that drop downlist using LDAP. Can any one plz help me out
How to add a DropDown List in Flex DataGrid
How to add a DropDown List in Flex DataGrid  hi I am trying to add a DropDownList in a DataGrid table. After the user selects one of the items from... select from one of the choices in the list. That's my reason for trying to add
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
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, how to dynamically increase size of list box in javascript when elements retrieving from database.. That is whenever I
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
retrive the data from access database to drop down list box in jsp
retrive the data from access database to drop down list box in jsp  hai, im new to jsp now im using the jsp along with access database.in table i load all the data's i need to retrive the data from database to dropdown list box
data should not repeat in the drop down list when it is loading dynamically from database
data should not repeat in the drop down list when it is loading dynamically... for loading the data dynamically from the data base but my problem is it is retrieving the whole department field from the data base (i.e in the drop down list
getting and storing dropdown list in database in jsp
getting and storing dropdown list in database in jsp  i have a drop down list to select book from database. i'm able to retrieve dropdown list from database. but unable to store the selected value in database table. please help
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
data should not repeat in the drop down list when it is loading dynamically from database
the data dynamically for database but my problem is in the list the same...data should not repeat in the drop down list when it is loading dynamically from database  selDept.jsp <%@page import="java.sql.*"%>
data should not repeat in the drop down list when it is loading dynamically from database
data should not repeat in the drop down list when it is loading dynamically from database  selDept.jsp <%@page import="java.sql.*"%> <..._NO`) ); the data is coming from
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
how to get data from database into dropdownlist in jsp
tutorial go through the link JSP Get Data Into Dropdown list From Database   ...how to get data from database into dropdownlist in jsp  Can anybody... the database and set it into dropdown list in jsp please help <br/>
Calling Servlet to build a List of data from database and show this on the JSP page in table
Calling Servlet to build a List of data from database and show this on the JSP... to retrieve all the data from database and then add the data into list. The list... list from database and how it can be added to the request object and sent
dropdown list in jsp
dropdown list in jsp  hai, i have static dropdown list.. i want to get the selected value in string variable without jsp regards asha
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  //Customer Name: <select name="name"> <% try{ Class.forName...="select * from staff"; ResultSet rs=st.executeQuery(sql); while(rs.next
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Customer Name:<select name="name"> <% try{ Class.forName...=con.createStatement(); String sql="select * from staff"; ResultSet rs
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...+",'"+email+"')"); out.println("Data is successfully inserted into database...(); in the below example. the error is "cannot convert from java.sql.Statement
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database) My question is when i select a particular value it should be pass
Populate dropdown menu from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet  please i need code to populate dropdown menu from mysql database using jsp and servlet. thanks
How to read data dynamically from keyboard to array in flex
How to read data dynamically from keyboard to array in flex  How to read data dynamically from keyboard to array in flex
how to use dropdown list in JSP and display value in same page
how to use dropdown list in JSP and display value in same page  I have a Dropdown list with some values say "A", "B" and "C" When the user selects... in the same page Value selected = C How can we do this in a JSP page
How to add dynamically rows into database ?Need help pls
How to add dynamically rows into database ?Need help pls  Hi everyone...; <input type="button" value="Add Row" onclick="addRow();" /> <input...')"; $result = mysqli_query($link, $query) or die('Error querying database
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
retrieving data in to the dropdown box from postgresql database in core java
retrieving data in to the dropdown box from postgresql database in core...); p2.add(b1); add(p1, "Center"); add(p2, "South...=st.executeQuery("SELECT role_name from role WHERE dept_id=1234"); if(rs
How we delete a data of database from front end jsp page
How we delete a data of database from front end jsp page   I make a website and featch a data from data base and now i want that a delete button put... deleted from jsp page as well as from database.I used mysql and jsp. Please help me
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a dropdown list. I want to set the dropdown list selected
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a dropdown list. I want to set the dropdown list selected
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  hello My Netizen friend has given the answer to retrieve data from the database... database using JSP Get data from database using JSP
How to backup a selected file from the dropDown Menu in JSP?
How to backup a selected file from the dropDown Menu in JSP?  I am trying to create a dropdown menu list for some type of files contained ina... file into the backup directory. I need the jsp code that can generate
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
How to get data from Oracle database using JSP
How to get data from Oracle database using JSP  hello i have a simple problem in jsp in the sense to get data from the database like oracle . I have... data from the database like oracle), I have created one jsp program like
how to store the data in a array retrived from the database - JSP-Servlet
how to store the data in a array retrived from the database  hi... in database,and i need to disply all the employees record in a single jsp. pls can any one tell me how to do it this using jsp. thankyou,  Hi nagaraj
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
How to Retrieve data from database in jsp
How to Retrieve data from database in jsp In this section we will discuss about how to fetch data from database table. We will give a simple example which will demonstrate you about fetching data from database table. Example We
How to change the data in the table dynamically ?
How to change the data in the table dynamically ?  This is my code. I want to add a sort button in the page and if i select any sort option then the data displayed in the table below should get sorted dynamically in this jsp page
Advertisements
 

 

 

DMCA.com