Home Answers Viewqa JSP-Servlet values of Combo boxes are not stored in database

 
 


Vijay
values of Combo boxes are not stored in database
2 Answer(s)      3 years and 2 months ago
Posted in : JSP-Servlet


i have some combo box values.
when i click the submit button after select combo box values, the values are not going in database.
please review the code:

<%
if((school.equals("indus"))||(school.equals("dps"))||(school.equals("mdn")))
{
if(value!=null && (value.equals("result")))
{ %>

<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("logic.jsp?school=<%=school%>&&class_name="+cla+"&&from_year="+y1+"&&to_year="+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>
</table>
</form>
<%
}

}
%>

code in logic.jsp:

<%
String class_name=request.getParameter("class_name");
System.out.println("class_name is"+class_name);
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;

// Connect with a full url string
con = DriverManager.getConnection("jdbc:odbc:sql;user=sa;password=1234");
System.out.println("First connection ok.");

// Connect with a url string and properties

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 Result WHERE year BETWEEN '"+from_year+"' AND '"+to_year+"' and school='"+school+"'";

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............");

while(rs.next())
{System.out.println("yes...now in rs block............");
%>

<tr align="center">
<td width="150"height="30"><%out.println(rs.getString(1));%>
<td width="150"height="30"><%out.println(rs.getString(2));%>
<td width="150"height="30"><%out.println(rs.getString(3));%>
<td width="150"height="30"><%out.println(rs.getString(4));%>
<td width="150"height="30"><%out.println(rs.getString(5));%>
<td width="150"height="30"><%out.println(rs.getString(6));%>
<td width="150"height="30"><%out.println(rs.getString(7));%>
<td width="150"height="30"><%out.println(rs.getInt(8));%>
<td width="150"height="30"><%out.println(rs.getString(9));%>
</tr>

<%
}
rs.close();
con.close();

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

kindly help:
View Answers

April 6, 2010 at 5:17 PM


Hi Friend,

Try the following code:

1)page.jsp:

<form method="post" action="allow.jsp">
Select School<select name="school">
<option value="indus">indus</option>
<option value="dps">dps</option>
<option value="mdn">mdn</option>
</select>
<input type="submit" value="submit">
</form>

2)allow.jsp:

<%
String school=request.getParameter("school");
System.out.println(school);
if((school.equals("indus"))||(school.equals("dps"))||(school.equals("mdn")))
{
%>
<jsp:forward page="select.jsp"/>
<input type="hidden" name="school" value="<%=school%>">
<%
}
%>

3)select.jsp:

<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("display.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">
<%

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>

April 6, 2010 at 5:19 PM


continue....

4)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);}
%>

Thanks









Related Pages:
values of Combo boxes are not stored in database - JSP-Servlet
values of Combo boxes are not stored in database   i have some combo box values. when i click the submit button after select combo box values, the values are not going in database. please review the code: function
combo boxes
combo boxes  how do you store numbers in the choices. ex. soda is $.75 and tax is $.07 then it equals a new total. I've been trying to use the Itemlistener but i can't figure out how to store the numbers import javax.swing.
Populate a combo box using data from a database
of some help, so i have three combo boxes, the first is supplier, the second... combo box which will then load the next combo box values, now i know how... a search on the database for the values I want, but then how do I pass that back
JavaScript Dynamic Combo Box
. For this, we have created two combo boxes where combo1 represents countries and combo2 represents the cities. The values of the combo boxes are stored...: On selecting the value from the first combo, related values will get displayed
How to write a select box and id should be stored in database?
How to write a select box and id should be stored in database?  Hi...) should be stored in database using SWINGS concept plz help   You... the id value into the database according to the name selected from the drop down
JSP combo and text field related questio
JSP combo and text field related questio  in JSP,i had stored data from database in a textboxes usin combo..now i want to use these values of text fields into another page(next page)..i tried it by using request.getparameter
Why the null values are stored in Database when I am sending proper values?
Why the null values are stored in Database when I am sending proper values... but the other details are not stored in the Database. Instead of other values, there null values are stored in the Database. Please guide me. Ask any more details
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
Label.setText showing square boxes for non english locales
the value from database according to the locale passed.But the values are getting displayed as square boxes when locale is passed other than english locale...Label.setText showing square boxes for non english locales  Hi, I am
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
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
Handling multiple combo boxes of same name - IDE Questions
Handling multiple combo boxes of same name  my code is like this.. i'm...' combo. i want no. of 'csubject' on the browser.. I hope.. i'll get solution
How to retrieve data by using combo box value in jsp? - JSP-Servlet
stored Combobox values from database...How to retrieve data by using combo box value in jsp?  I am using
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database  Hi Friend, Try the following code...("insert into file(file_data) values(?)"); //psmnt.setString(1,saveFile); fis
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
How to retreive data by using combo box value - JSP-Servlet
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  I am using a single
DATABASE
DATABASE  How can i get combo box values from database?? or how can i get values in the drop down menu of the html which is similar to dat of combo box in java - from database
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
selected values directly from the Database and not adding to it as an extra one...Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB  The below
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
Resize image stored in database
Resize image stored in database  hi, Can any one please send code for how to resize image stored in database in blob datatype in jsp, i want to resize it to 140(w)*160(h) please help me
Retriving data stored in database
Retriving data stored in database  Hi, How to retrive data from my sql database using Hibernate,Spring and tapestry please give me an example.I am new to this Hibernate and Spring
Displaying database values in pdf format
the form the values are stored in database,the database name is registration...Displaying database values in pdf format  Hi All, I am... database values should be shown as pdf or excel format. Thanks in advance
Stored procedures
Stored procedures  hello What are stored procedures?   hello, A stored procedure is a set of statements or commands which reside in the database. The stored procedure is precompiled. Each Database has it's own
where are program instructions and data values stored
where are program instructions and data values stored  Where are program instructions and data values stored in Computer?   In Storage. Actually, whichever program and data we use in our computers are stored in Storage
Stored Procedures and Functions
Stored Procedures and Functions       Stored Routines (Procedures and Functions) are supported in version MySQL 5.0. Stored Procedure is a set of statements, which allow ease
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter... the database will get displayed on the ComboBox. If there will be  no data
Insert Data in Table Using Stored Procedure
into a table using stored procedure. Steps: 1.Create database: To create database we use syntax: create database database_name. We can create database... Insert Data in Table Using Stored Procedure   
combo box
combo box  Hi, [_|] dropdown box... usernames from the database & upon selection of particular user i should get... in database User table and UserModule table. Please help me
Store values of dynamically generated textboxes into database
Store values of dynamically generated textboxes into database   I'm... for example the user enters 3 into textbox, three text boxes get generated in the new frame. now when the user write data into these text boxes I want
database
database  How can i get combo box values from database?? or how can i get values in the drop down menu of the html which is similar to dat of combo box in java - from database? you had given me the answer <%@page
check all database stored procedures - JDBC
check all database stored procedures  How to check all database stored procedures in Java
Store combo box value - Development process
Store combo box value  Hi , this is my code. Here wen i click submit button combo values are stored like 1,2,3... but i want to store value . plz... = request.getParameter("Combo"); String Issue = request.getParameter("IssueName"); String
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 appears named Subject values Arts, Commerce, Science. how i conditional
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
or .txt) file and get the values from that file and store them into database... stored in database like names(column) siva divya ravi one value for one...how to read the values for text and csv files and store those values
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
Stored Procedure and Trigger
Stored Procedure and Trigger  hello, What is the difference between Stored Procedure and Trigger ?   hii, Triggers once defined are called automatically, there can be no explicit invocation Stored procedure has
DropDown and text boxes with AJAX, JSP - Ajax
DropDown and text boxes with AJAX, JSP  Hi, we are using one drop down and two text boxes. Drop down values needs to be retrive from one table.we... in the text boxes onblur it needs to validate whether the inserted values
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... combo boxes.   Here is Java swing code: import java.sql.*; import
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
What is Stored Procedure?
What is Stored Procedure?  What is Stored Procedure?   Hi, Here is the answer, A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored
How to passed the ID's in MAP how to stored whaterver select the name that only ID should store in db using SWING/AWT?
ever the name is selected that id should be stored in database how to passed the ID's in MAP how to stored whaterver select the name that ID should store...How to passed the ID's in MAP how to stored whaterver select the name that only
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... table country(country_id,country) in database and try the following code
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
supplying values to in parameters of stored procedure in ms sql and displaying out parameters
supplying values to in parameters of stored procedure in ms sql and displaying out parameters  I have to execute following procedure ALTER PROCEDURE [dbo].[get_date] @codeId int, @vardate as datetime OUTPUT AS SELECT
combo program - Java Beginners
combo program  I want to give DOB in combo box for that i have to give 1 to 30 for days and 1900 to 2010. Without giving all, using for loop i have to get the values. Please help me..   Hi Friend, Please visit
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... with the database table. What is the connection string that i am suppose to write
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...... For Example, in Student.jsp... when i click student id in combo box
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..., you need to create two database tables: 1)country CREATE TABLE `country

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.