Enter your email address:

Delivered by FeedBurner


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display combo box value/Database value on same JSP page
12-19-2011, 04:57 PM
Post: #1
Thumbs Up Display combo box value/Database value on same JSP page
Today we are going to learn how to

Display combo box value/Database value on same JSP page

Here we are getting values from a combo box and check it with the database and display the values in the same jsp page.
First create the table

create table Result(year varchar(20),class varchar(20),Subject varchar(20),total_students varchar(20),passout_students varchar(20),marks_obtained_60_to_80varchar(20),marks_obtained_above_80 varchar(20),overall_result varchar(20));

Now in the jsp page itself we are displaying a combo box and a button when we press the button the corresponding class values is displayed in the below field.

<%@page import="java.sql.*,java.io.*;"%>

Quote:<tr>

<td width="60"height="30">
<form name="s" action="#" method="get">
<select name='class_name'>

<%

for(int i=1;i<12;i++)

{

out.println("<option value="+i+">"+i+"</option>");

}

%>

</td>

<select name='from_year'>

<%

for(int i=2010;i>2000;i--)

{

out.println("<option value="+i+">"+i+"</option>");

}

%>

</td>

<td>

<select name='to_year'>

<%

for(int i=2010;i>2000;i--)

{

out.println("<option value="+i+">"+i+"</option>");

}

%>


Quote: </td>

<td>

<input type="submit" name="submit" value="Go" ></td>
</form>
</tr>

<table align="center" border="1" align="center">

<br>

<tr bgcolor="#36559E" align="center">

<td width="150"height="30"><font size="+1">Year</td></font>

<td width="150"height="30"><font size="+1">Class</td></font>

<td width="150"height="30"><font size="+1">Subject</td></font>

<td width="150"height="30"><font size="+1">Total Students</td></font>

<td width="150"height="30"><font size="+1">Passout Students</td></font>

<td width="150"height="30"><font size="+1">Marks Obtained 60 To 80</td></font>

<td width="150"height="30"><font size="+1">Marks Obtained over 80</td></font>

<td width="150"height="30"><font size="+1">Overall Result</td></font>

</tr>

<%

String submit=request.getParameter("submit");

if(submit!=null && (submit.equals("Go")))

{

String class_name=request.getParameter("class_name");

out.println("class_name is"+

class_name);

Connection con ;

try {

// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;

Class.forName("com.mysql.jdbc.Driver") ;

// con = DriverManager.getConnection("jdbc:odbc:sql;user=sa;password=1234");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
out.println("First connection ok.");

out.println("Connection created");

Statement st=con.createStatement();

out.println("st going to execute");

String query="select year, class, Subject, total_students, passout_students,

marks_obtained_60_to_80, marks_obtained_above_80, overall_result from Result where

class='"+class_name+"' ";

out.println("now data are selecting");

ResultSet rs=st.executeQuery(query);

System.out.println("now data in rs.....");

out.println("now going to rs block............");

while(rs.next())

{out.println("now in rs block............");

%>


Quote:<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.getString(8));%>
</tr>

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

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

%>


Now you can able to get the same value from the database in same page.

Happy coding
Find all posts by this user
Add Thank You Quote this message in a reply
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
Post Reply 


[-]
Share/Bookmark (Show All)
Facebook Linkedin Technorati Twitter Digg MySpace Delicious

Possibly Related Threads...
Thread: Author Replies Views: Last Post
Sad how to import a csv file values in to database using jsp rajasri 2 1,211 02-20-2012 12:17 PM
Last Post: rajesh2407
Big Grin In Tomcat jsp page is not refreshing rajasri 0 198 12-19-2011 06:11 PM
Last Post: rajasri
Lightbulb compare current time with database retrieved time in jsp rajasri 0 200 12-19-2011 05:17 PM
Last Post: rajasri
Its My Birthday! Display database value in jsp page rajasri 0 609 12-14-2011 11:43 AM
Last Post: rajasri
Video simple update query in jsp page rajasri 0 1,067 12-14-2011 11:36 AM
Last Post: rajasri
Shocked update using parameters in jsp page rajasri 0 434 12-14-2011 11:34 AM
Last Post: rajasri
Big Grin using session to protect a page in jsp rajasri 0 583 12-13-2011 12:17 AM
Last Post: rajasri
Video Display current time and date in your Jsp page rajasri 0 957 12-12-2011 11:56 PM
Last Post: rajasri
Star Getting number of rows in jsp page rajasri 0 587 12-12-2011 11:53 PM
Last Post: rajasri
Star Read data from xml and show in jsp page project download rajasri 0 950 12-12-2011 11:30 PM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)