Acees data from database using combo box

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 value 11 or 12, otherwise combo box combo2 remain hide.

Here is JSP's files:

Here is JSP file:-
display.jsp:

<html>
<head>
<body>
<form name="form" >
<table align="center">

<script language="javascript">
function sendData(){
var sch=document.form.school.value;
var cla=document.form.class_name.value;
var y1=document.form.from_year.value;
var y2=document.form.to_year.value;
window.open("show.jsp?class_name="+cla+"&&from_year="+y1+"&&to_year="+y2+"&&school="+sch);
alert(sch+" "+cla+ " "+y1+" "+y2);
}

function hide(){
if (document.getElementById){
document.getElementById('combo').style.visibility = 'hidden';
}
}
function call(class_name){
var val = class_name.options[class_name.selectedIndex].text;
if((val=='11')||(val=='12')){
document.getElementById('combo').style.visibility = 'visible';
var arr = new Array();
arr[11] = new Array("Art","Commerce","Science");
arr[12] = new Array("Art","Commerce","Science");
var comboValue = class_name.value;
document.forms["form"].elements["combo2"].options.length=0;
for (var i=0;i<arr[comboValue].length;i++)
{
var option = document.createElement("option");
option.setAttribute('value',i+1);
option.innerHTML = arr[comboValue][i];
document.forms["form"].elements["combo2"].appendChild(option);
}
}
else{
document.getElementById('combo').style.visibility = 'hidden';
}
}
</script>
<body onload="hide();">

<p></p><br><br><br><br><br><br>
<tr><td style="width: 11px"> <span>Class</td> <td><select name="class_name" onchange="call(this); >
<%

for( int i=1;i<=12;i++){
%>
<option value="<%=i%>"><%=i%></option>
<%
}
%>
</select><td>
<select id="combo" name="combo2">
</select></td>

<tr><td style="width: 11px"> <span>From Year</td><td><select name="from_year">
<%
for(int j=2000;j<=2010;j++){
%>
<option value="<%=j%>"><%=j%></option>
<%
}
%>
</select></td></tr>
<tr><td style="width: 11px"> <span>To Year</td><td><select name="to_year">
<%
for(int k=2000;k<=2010;k++){
%>
<option value="<%=k%>"><%=k%></option>
<% } %>
</select></td></tr><td></td>
<tr><td style="width: 11px"> <span><input type="button" value="Result" onclick="sendData();"></td></tr>
<tr><td><input type="hidden" name="school" value="<%=request.getParameter("school")%>"></td></tr>
</table>
</form>
</body>
</head>
</html>


kindly help.
View Answers

April 8, 2010 at 5:01 PM

Hi Friend,

1)select.jsp:

<%@page import="java.sql.*"%>
<%
String school=request.getParameter("school");
String class_name=request.getParameter("class_name");
System.out.println("class_name is"+class_name);
String from_year=request.getParameter("from_year");
String to_year=request.getParameter("to_year");
System.out.println(from_year+" "+to_year);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
System.out.println("First connection ok.");


System.out.println("Second connection ok.");

System.out.println("Connection created");
Statement st=con.createStatement();
System.out.println("st going to execute");
String query="SELECT * FROM student WHERE year BETWEEN '"+from_year+"' AND '"+to_year+"' and school='"+school+"'";
System.out.println(query);
System.out.println("now data are selecting");

ResultSet rs=st.executeQuery(query);
System.out.println("now data in rs.....");
System.out.println("now going to rs block............");
%>
<table>
<%
while(rs.next())
{System.out.println("yes...now in rs block............");
%>

<tr>
<td ><%=rs.getString(1)%></td>
<td ><%=rs.getString(2)%></td>
<td ><%=rs.getString(3)%></td>
<td ><%=rs.getString(4)%></td>
<td ><%=rs.getString(5)%></td>
<td ><%=rs.getString(6)%></td>
<td ><%=rs.getString(7)%></td>

</tr>

<%
}
%>
</table>
<%
rs.close();
con.close();

}catch(Exception e){out.println(e);}
%>

2)display.jsp:

<%@page import="java.sql.*"%>
<%
String school=request.getParameter("school");
String class_name=request.getParameter("class_name");
System.out.println("class_name is"+class_name);
String from_year=request.getParameter("from_year");
String to_year=request.getParameter("to_year");
System.out.println(from_year+" "+to_year);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
System.out.println("First connection ok.");


System.out.println("Second connection ok.");

System.out.println("Connection created");
Statement st=con.createStatement();
System.out.println("st going to execute");
String query="SELECT * FROM student WHERE year BETWEEN '"+from_year+"' AND '"+to_year+"' and school='"+school+"'";
System.out.println(query);
System.out.println("now data are selecting");

ResultSet rs=st.executeQuery(query);
System.out.println("now data in rs.....");
System.out.println("now going to rs block............");
%>
<table>
<%
while(rs.next())
{System.out.println("yes...now in rs block............");
%>

<tr>
<td ><%=rs.getString(1)%></td>
<td ><%=rs.getString(2)%></td>
<td ><%=rs.getString(3)%></td>
<td ><%=rs.getString(4)%></td>
<td ><%=rs.getString(5)%></td>
<td ><%=rs.getString(6)%></td>
<td ><%=rs.getString(7)%></td>

</tr>

<%
}
%>
</table>
<%
rs.close();
con.close();

}catch(Exception e){out.println(e);}
%>

3)show.jsp:
<%@page import="java.sql.*"%>
<%
String stream=request.getParameter("stream");
out.println(stream);
%>

Thanks









Related Tutorials/Questions & Answers:
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
Populate a combo box using data from a database
Populate a combo box using data from a database  Hi Guys, In need... to the client using ajax, and then populate the combo box, I must'nt reload... combo box which will then load the next combo box values, now i know how
Advertisements
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 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
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
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... getting data into textarea from database table by clicking on the button
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
retrieving from oracle database using jsp combo box
retrieving from oracle database using jsp combo box  hi this is my... name of the server has to display in the process name field from the oracle database please help on this i need code using servlets please help me . <
How to retrieve data by using combo box value in jsp? - JSP-Servlet
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...... i already stored combo box values from database. pl
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all... stored Combobox values from
How to retreive data by using combo box value - JSP-Servlet
How to retreive data by using combo box value  I am using a single... there... /// Here stored Combobox values from database. Note: I am using only this jsp form.. i do not use to get values from
How to retreive data by using combo box value - JSP-Servlet
How to retreive data by using combo box value  Hello friend... the values from html. So u r using if(request.getParameter("cid")!=null... I can print combo box values
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to retrieve data using combo box value in jsp?  Hi freind, I already post this question. I need urgent help from u. pl response me.... All actions in the same page.......  Hi Friend, Please visit
How to retrieve data by using combo box value in jsp? - JSP-Servlet
in combo box from database.. by using select*from studentinformation; But when i...How to retrieve data by using combo box value in jsp?  Hi Friends... related value.... I am using only this page.. not get value from another page
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
How to show autocomplete textbox values on combo box option selection using database?
How to show autocomplete textbox values on combo box option selection using database?  When I select option(i.e First Year) then it will show list of student names in auto-complete text box
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
how to retrieve data into combo from database in java applet?
how to retrieve data into combo from database in java applet?  hi,. i have written applet codes for linking two frames and database connectivity but the problem is, the database is not retrieving data into the combo..please
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
retrieve data from database using jsf
retrieve data from database using jsf  Hello I want an example of source code to retrieve data from database i have a database (oracle) name as db1 it's contain table 'author' composed of three columns idauthor(primary key
Use of Select Box to show the data from database
Use of Select Box to show the data from database   ... page to show the data fetched from the database. We are using Servlet to get data from the database using MySQL and we are forwarding this servlet data
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...=st.executeQuery("SELECT role_name from role WHERE dept_id=1234"); if(rs... database: import java.sql.*; import java.awt.*; import javax.swing.*; import
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <... searchProduct(SearchDTO sdto) { String query="select * from product
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
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes... QueryString = "SELECT * FROM code<em>ot WHERE code</em>codeot=12
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... upload excel file and update database using JSP ? Thanks in Advance
view data from database using drop down list
view data from database using drop down list  hi i want to view the data from database by selecting a value in a drop down list. for an example drop down list have picture element.when click it select pictures from the database
place data in text fields from database using jdbc
place data in text fields from database using jdbc  i want get the data from database and place the records in the respective textfields using jdbc and swing like eno,ename,loc from emp table
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
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
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 get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... the problem   Get data from database using servlet Retrieve data from database using JSP Get data from database using JSP
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?   try{ Session session = HibernateUtil.getSessionFactory().openSession...); System.out.println("Successfully data insert in database"); tx.commit
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 retreive data from database without using post method in jsp - JSP-Servlet
How retreive data from database without using post method in jsp  Tell me how?  Hi Friend, If you don't want to use post method then use... the selected value from the combo box and get textbox value from another page
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть свой сервер! Хорошая атмосфера
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp   the user can create an event. In the create page, we have three buttons. Save as draft... the contents from the db based on the event id. But this jsp url should be a public
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... the answer to retrieve data from the database by using servlet or jsp program
how to insert data from database using oops concepts - Development process
how to insert data from database using oops concepts  Hi, How to insert data from database using oops based concepts.please write the code and send me.using class and constructor..its urgent  Hi Friend, Try
retrive data from database?
retrive data from database?  hellow i have a database sheet name... from db1 and enter value in text box according there name,rollno and save... as |------------------------| |sn.|rollno|name|text box

Ads