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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Vijay
values of Combo boxes are not stored in database
2 Answer(s)      4 years and 9 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:

Advertisement
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:
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.
Advertisements
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 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
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
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
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... displaying path that is stored in the database but not the image itself. Kindly
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
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
check all database stored procedures - JDBC
check all database stored procedures  How to check all database stored procedures in Java
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
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
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
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
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
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
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
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
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 the value of combo box . I am not getting it plz help me out .   hi
how to display or retrive an image in jsp whose path is stored in oracle database
how to display or retrive an image in jsp whose path is stored in oracle database  how to display or retrive an image in jsp whose path is stored in oracle database and the image is stored in my pictures folder
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
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
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB   Hello, This is for Updating. I had two SQL queries one for only selected values
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
show the database values graphical represantation
show the database values graphical represantation   show the database values graphical represantation and auto refresh for every 30 secand displaying in webpage
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
HTML(Registration form) to Jsp to stored into MS ACCESS database
HTML(Registration form) to Jsp to stored into MS ACCESS database  i am sending one html file that contain 18 fields these are stored in ms-access database by using jsp code.i want to urgent jsp code. please urgent sir. thank
Advertisements
 

 

 

DMCA.com