|
Display combo box value/Database value on same JSP page
|
|
12-19-2011, 04:57 PM
Post: #1
|
|||
|
|||
|
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> <% 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> <% 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"> <% } 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
|
|||
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
User(s) browsing this thread: 1 Guest(s)






![[-]](images/royal_red/collapse.gif)






