0

my question is related to JSP and HTML.
i have a jsp page which have three combo box and a button.
one combo box for a class. two combo box for from_year, to_year.
i want to reterive data on this same JSP page from database based on
combo box value.
my requirement is after select the item from combo boxes then i click
to button, table could be show the data based on criteria of combo box
value on the same Jsp page.

presently, i am checking for a one combo box.

i tried this but no suceesull:

<tr>
<td>

<select name='class_name'>
<%
 for(int i=1;i<12;i++)
 {
 out.println("<option value="+i+">"+i+"</option>");
 }
 %>
 </td>
 <td>
 <input type="submit" name="submit" value="Go" ></td>
 </td>

 <%
 String submit=request.getParameter("submit");
 if(submit!=null && (submit.equals("Go")))

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

 // database connectivity

 %>

please suggest.

3
Contributors
3
Replies
7
Views
7 Years
Discussion Span
Last Post by peter_budo
1

there is my code. please correct where is wrong.

<tr>
<td width="60"height="30">
<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>");
}
%>
</td>

<td>
<input type="submit" name="submit" value="Go" ></td>
</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");
System.out.println("class_name is"+
class_name);
  Connection con = null;
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;


      con = DriverManager.getConnection("jdbc:odbc:sql;user=sa;password=1234");
      System.out.println("First connection ok.");
    

System.out.println("Connection created");
Statement st=con.createStatement();
System.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+" ' ";

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("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);}

}
}
%>
0

@vij123

1. Slap on hand for doing database connectivity directly from JSP
2. I do not think you want to learn new technology like JSF or Apache Velocity, the only option I can offer for dynamic data without previously mentioned technologies is to use asynchronous AJAX or jQuery calls to servlet to get data

Edited by peter_budo: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.