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:
<%
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 Tutorials/Questions & Answers:
Advertisements
combo boxescombo 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.
Resize image stored in databaseResize 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 databaseRetriving 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
Retrieving Data from Database to fill Combo BoxRetrieving 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... displaying path that is
stored in the
database but not the image itself. Kindly
where are program instructions and data values storedwhere 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
edit values of database using jspedit
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 jspedit
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
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
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
get values from Excel to databaseget
values from Excel to database hi i want to insert
values from Excel file into database.Whatever field and contents are there in excel file that should go to
database which exists. am using SQL Server management studio
Database values in JComboBoxDatabase 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
image upload and stored in database - JSP-Servletimage 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
Acees data from database using combo box - JSP-ServletAcees 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
JPA 2.1 Stored Procedure Example in MySQL
database and then call the
stored procedure in your JPA 2.1 based... this language is called
PL/SQL. Oracle
database server also supports
stored procedure... to create
stored
procedure.
Stored procedures are
database specific and
stored problem in setting the values from database the
values from
database.
here is the code:
private JTextField getJTextField1...problem in setting the
values from database hello friends,
can... Stmt after setting the
values " + pst.toString());
rs
DATABASEDATABASE 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 insert values from excel file into database the following link:
Insert
values from excel file to
database...insert
values from excel file into database hi i want to insert
values from Excel file into database.Whatever field and contents are there in excel
getting values from database - JSP-Servlet JSP code separately.If it will not display
database values then try your code...getting
values from database I tried the following code
abc.html
aaa.jsp
I am not getting exceptions now
store values of drop down list box in database store
values of drop down list box in database how to store
values of drop down list box in oracle
database in jsp?I have information inserting form where i have date of birth as drop down list box
How to create bar chart using database valuesHow to create bar chart using
database values How to create bar chart using
database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
validation before entering values into database in jspvalidation before entering
values into
database in jsp Hi,
my project involves entering data into
database from jsp form.but before entering into
database it should pop up a alert message that "you have selected product:name
Inserting values in MySQL database table Inserting
values in MySQL
database table
... to
insert the
values in the
database. Here we are going to see, how we can insert
values in
the MySQL
database table. We know that tables store data in rows