Home Answers Viewqa JSP-Servlet same thing i want but from db..

 
 


farooq s
same thing i want but from db..
4 Answer(s)      8 months ago
Posted in : JSP-Servlet

http://www.roseindia.net/tutorial/javascript/dynamicCombo.html

same thing i want but from db..

View Answers

August 28, 2012 at 6:09 PM


Here is a jsp application that retrieves data from the database and stored into first dropdown. If user click any option from the dropdown, the corresponding values will get displayed into another dropdown.

1)selDesg.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='desg' 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 desg");
 while(rs.next()){
     %>
      <option value="<%=rs.getString("DESG_NO")%>"><%=rs.getString("DESIGNATION")%></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 DESG_NO='"+no+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString("EMP_NAME")+"'>"+rs.getString("EMP_NAME")+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

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

1)desg:

CREATE TABLE `desg` (                     
          `DESG_NO` int(100) default NULL,        
          `DESIGNATION` 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,                         
          `DESG_NO` int(100) default NULL,                        
          `DEPT_NAME` varchar(100) default NULL,                  
          PRIMARY KEY  (`EMP_NO`)                                 
        );

August 29, 2012 at 10:30 AM


thank u for ur answer : but i need onclick SE(softwware eng) i should get a list of SOFTWARE ENG's similary .. HE(hardware eng) i should get a list of Hardware eng'r... if i click SE SE: HE ratan justin farooq martin sham ram rahul Deepak from database..

Thank YOu


August 29, 2012 at 10:31 AM


SE: martin sham ram rahul Deepak HE: ratan justin farooq


August 29, 2012 at 10:46 AM


hey i got it thank you









Related Pages:
same thing i want but from db..
same thing i want but from db..  http://www.roseindia.net/tutorial/javascript/dynamicCombo.html same thing i want but from db
How to load elements from db when i press next.
but i want to show only 20 at the time and there will be 5 buttons for next page means when i click next, the next 20 books will be displayed from db on the same...How to load elements from db when i press next.  Hello , I am working
Want to access my Ms-access Db file which is placed inside the same Jar file
Want to access my Ms-access Db file which is placed inside the same Jar file  how do i access my Ms-Access file placed in the same jar file where my application code/class file r present??? Want to access it via Code
Server DB connection - JDBC
Server DB connection  Hello Guys I want to connect two databases.... One database is on my localhost and the other one is on server, I want to transfer the data from my localhost database to the database on the server. I have
i want to retriev and update in same form but its not working pls help....
i want to retriev and update in same form but its not working pls help....  <p><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN...("refno"); re=stmt.executeQuery("select * from passapp where refno='"+refno
to upload a table from DB to the same html page
to upload a table from DB to the same html page  how to make this booklist table to be opened in the same html page itself using a third frame
JSP,DB
:"select * from datatable where id="'+id'"" I want to get the values here... to the diagram given above??now I want to retrive the value of application no and master no into a jsp page?for this I thought of storing the resultset of my query
View Photo From Db MySql
View Photo From Db MySql  Good Morning Sir, Please help me, I make a small code but i have a error. I want to make viewer photo from database...(); ResultSet res = stat.executeQuery("select * from kar where nik
Read data from Excel and insert in to DB and export data from DB to Excel
Read data from Excel and insert in to DB and export data from DB to Excel  Read data from Excel and insert in to DB and export data from DB to Excel Hi, I need to read the data from excel and I need to insert the same in to DB
JSP,DB,SERVLET
JSP,DB,SERVLET  hi thank you for your reply.With this code i can insert the data successfully into database but once i give submit button in insert.jsp it should be forwarded to ajax.jsp.In ajax.jsp once i give the name;;;age
I want this jsp answers
I want this jsp answers    How can we declare third party classes... jsp is subclass to HttpJspBase.Here HttpJspBase is from which package? HttpJspBase is subclass to HttpServlet(Y/N)? All over rided methods from the HttpServlet
I want this jsp answers
I want this jsp answers    How can we declare third party classes... jsp is subclass to HttpJspBase.Here HttpJspBase is from which package? HttpJspBase is subclass to HttpServlet(Y/N)? All over rided methods from the HttpServlet
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, My previous Query that: I want to add the Image In databse using servlet. I have a program Its fine... through servlet.But Sir, I am using weblogic so I do not want the reference
Want to display Arraylist items on same row in JSF
Want to display Arraylist items on same row in JSF  I want do display values of one arraylist on same row using datatable? If i use h:column, then it goes on different row. Please tell me, how I can do it?   Hi Friend
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query that: I want to add the Image In databse using servlet. I have a program Its fine... the image through servlet.But Sir, I am using weblogic so I do not want the reference
db
* from producttest"; rs = statement.executeQuery(QueryString);%> <
db
* from producttest"; rs = statement.executeQuery(QueryString);%> <
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I... with a and from that i need to select the required value and i should store
manipulating dat retrieved from the DB using php arrays
manipulating dat retrieved from the DB using php arrays  am querying the DB as follows: $`result=mysql_query("SELECT name,itemquantity FROM mytable WHERE price='$price'");` now,i want to create an array to insert the values
manipulating dat retrieved from the DB using php arrays
manipulating dat retrieved from the DB using php arrays  am querying the DB as follows: $`result=mysql_query("SELECT name,itemquantity FROM mytable WHERE price='$price'");` now,i want to create an array to insert the values
manipulating dat retrieved from the DB using php arrays
manipulating dat retrieved from the DB using php arrays  am querying the DB as follows: $`result=mysql_query("SELECT name,itemquantity FROM mytable WHERE price='$price'");` now,i want to create an array to insert the values
retrieve value from db in text box + calendar implementation.
retrieve value from db in text box + calendar implementation.  I... there is already a text box..Now i want to get the value retrieved from database in that text field how can i do it... Please help...   Please visit
I am from .net background, I want to learn SOA.
I am from .net background, I want to learn SOA.  Hi I am from .net background, I want to learn SOA. Could it possible for me to learn SOA, I suppose SOA includes Java. I dont have knowledge of java. Please help Thanks  
i want to show timeline chart for three year in chart..
i want to show timeline chart for three year in chart..  I am using Jfree chart library to display chart in web pages. i want to show three year data in chart in 3 lines for three year in same chart. i am able to show
manipulating dat retrieved from the DB using php arrays
manipulating dat retrieved from the DB using php arrays  am querying the DB as follows: $`result=mysql_query("SELECT name,itemquantity FROM mytable WHERE price='$price'");` now,i want to create an array to insert the values
retrieving image from mysql db with standard height and width
retrieving image from mysql db with standard height and width  Hi . Here is my code to retrieve an image from mysql db. Its working properly. But i want the image with specified width and height. How to specify it in this code
retrieving image from mysql db with standard height and width
retrieving image from mysql db with standard height and width  Hi . Here is my code to retrieve an image from mysql db. Its working properly. But i want the image with specified width and height. How to specify it in this code
retrieving from db - JSP-Servlet
retrieving from db  hello' I am trying to write my first application connecting to the database. I have found some code but i am getting the following errors wen i am running the prg. the error is as follows. I can't figure
How to disable Browser's back button (at the same time i want my own back button to be enabled) :p
How to disable Browser's back button (at the same time i want my own back button to be enabled) :p  Hi, I have designed a "back" button for jsp page. Now I want to disable Browser's default button So that people will use "back
How to disable Browser's back button (at the same time i want my own back button to be enabled) :p
How to disable Browser's back button (at the same time i want my own back button to be enabled) :p  Hi, I have designed a "back" button for jsp page. Now I want to disable Browser's default button So that people will use "back
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
Pass cookie from one site to another within the same domain
Pass cookie from one site to another within the same domain  Hi, I want to pass a cookie from one website to another within the same domain. This is just to identify whether the same user is logged in or not. Can anyone help me
j2me with derby db - MobileApplications
j2me with derby db  Hello, Presently Iam working on the j2me(wireless toolkit2.0).I have done so many applns in j2me,but I want to install derby db in j2me.I am new to derbydb. Can u tell me briefly abt derby db,which version
Zend Db error - WebSevices
Zend Db error  Hello friends, How i get the values from the database using zend framework Any one know the code. Help me
retrieving info from DB using struts?
retrieving info from DB using struts?  Hi. I was looking info about retrieving info from a database using struts. I need a .java that I suppose connects to a database and show the info on a jsp. Somebody could help me
I want design samples for JSP project
I want design samples for JSP project  Sir, I world Like to do a project in jsp techonology. But i have no idea of selecting the project, especially if i selected any project i have no idea that is how to build ie how to design
Learn some thing about ajax
Learn some thing about ajax  please provied some simple ajax code... small amount of data from web server and then showing it on your application. You..., this can be frustrating thing for the user, as whole page is reloaded only
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc
JSP,DB,SERVLET
JSP,DB,SERVLET  I have a jsp page with 3 text fields name,age ,city.i populated these datas into a database table.I have another jsp page with 4... be automatically populated from database throush servlet..Can u give me the code
i want to pass Javascript value to JSP scriptlet..
i want to pass Javascript value to JSP scriptlet..  i am having a problem that, i am having a combo box in the JSP page when i select an item from... now i want to pass this value to JSP scriptlet
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created... will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc.....i ve
I want code below mention programe
I want code below mention programe  Create a web application using any technology that accepts a keyword and displays 10 relevant tweets from Twitter in real-time for that keyword
i want to know how a slide will hide
i want to know how a slide will hide  when im click on the button then im getting a slide, but when im click on the another button this slide will be hide.. and here im using logic iterate to getting the values from action class
i want to know how a slide will hide
i want to know how a slide will hide  when im click on the button then im getting a slide, but when im click on the another button this slide will be hide.. and here im using logic iterate to getting the values from action class
how i want to create a coding by this question?
how i want to create a coding by this question?  Design and write a class named Person and its two subclasses named Student and Employee. Make... an object from each of these classes and invokes their toString() method
JSP,DB,SERVLET
JSP,DB,SERVLET  hi thank you for your reply.With this code i can insert the data successfully into database but In ajax.jsp once i give the name... in dose textfields....can u help me?????? Name: Ram I entered dtls of ram
JSP,DB,SERVLET
JSP,DB,SERVLET  I have a jsp page called page1.jsp with 3 text fields... (page1servlet.java) and bean(page1bean.java).I have another jsp page(display.jsp... should be automatically populated from database through servlet
i want to save image on server folder. and i want to save URL of this folder and name of image in database
i want to save image on server folder. and i want to save URL of this folder and name of image in database  hi i want to save image on server folder. and i want to save URL of this folder and name of image in database.on click
Entity DB design pattern - Java Interview Questions
Entity DB design pattern  I want the information for Entity DB design pattern
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.