data are not display in JSP from database

data are not display in JSP from database


i want to finding some data through a SQL query from SQL server database to a JSP page based on some condition which i specfied in parameters. but it is not going in while loop.
one.jsp

<%
String school=request.getParameter("school");
out.println(school);
String class_name=(String)request.getParameter("class_name");
String from_year=(String)request.getParameter("from_year");
String to_year=(String)request.getParameter("to_year");
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
con = DriverManager.getConnection("jdbc:odbc:sql");
System.out.println("Connection created");
Statement st=con.createStatement();
String query="select * from Result where school=('"+school+"') and (year='"+from_year+"') and (year='"+to_year+"')";
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............");
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
}
rs.close();
con.close();
}
catch(Exception e)
{
out.println(e);
}
%>


value of 'school' request parameter are comming from the link of this jsp page. like..
<a href="indus.jsp?value=result&&school=indus" class="smalltext">School Result</a>
and three request parameters 'class', 'from_year', 'to_year' are the value of three combo boxes. all request parameters are received in this jsp page.

.
but when i used this parameters on a criteria i am not finding any data.
it go only upto
now data in rs
now going to rs block

but it is not going in
while(rs.next())
{
..
.
..
}
sql server database having this fields- year,class, subject, total_students, passout_students, school.

but when i use this query it goes fine.
String query="select * from Result where school=('"+school+"') ";

please suggest.
View Answers

March 23, 2010 at 4:44 PM

Hi Friend,

Try the following code:

1)form.jsp:

<html>
<script>
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("result.jsp?school="+sch+"&&class_name="+cla+"&&from_year="+y1+"&&to_year="+y2);
}
</script>
<form name="form" >
<table>
<tr><td>School</td><td><input type="text" name="school"></td></tr>
<tr><td>Class</td><td><select name="class_name">
<%
for(int i=1;i<=12;i++){
%>
<option value="<%=i%>"><%=i%></option>
<%
}
%>
</select></td></tr>
<tr><td>From Year</td><td><select name="from_year">
<%
for(int i=2000;i<=2010;i++){
%>
<option value="<%=i%>"><%=i%></option>
<%
}
%>
</select></td></tr>
<tr><td>To Year</td><td><select name="to_year">
<%
for(int i=2000;i<=2010;i++){
%>
<option value="<%=i%>"><%=i%></option>
<%
}
%>
</select></td></tr>
<tr><td><input type="button" value="Result" onclick="sendData();"></td></tr>
</table>
</form>
</html>

2)result.jsp:

<%@page import="java.sql.*"%>
<%
String school=request.getParameter("school");
out.println(school);
String class_name=(String)request.getParameter("class_name");
String from_year=(String)request.getParameter("from_year");
String to_year=(String)request.getParameter("to_year");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
System.out.println("Connection created");
Statement st=con.createStatement();
String query="SELECT * FROM student WHERE year BETWEEN '"+from_year+"' AND '"+to_year+"' and school='"+school+"'";
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............");
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
}
rs.close();
con.close();
}
catch(Exception e)
{
out.println(e);
}
%>

For more information, visit the following link:

http://www.roseindia.net/jsp/

Thanks









Related Tutorials/Questions & Answers:
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
Advertisements
Display Data from Database in JSP
, to show data from the database click on the link that calls another .jsp file named...; <html> <head> <title>display data from...;To display all the data from the table click here...</h2></TD>
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...+",'"+email+"')"); out.println("Data is successfully inserted into database...(); in the below example. the error is "cannot convert from java.sql.Statement
jsp code for display of data from database and snap shot of the output
jsp code for display of data from database and snap shot of the output  i am using JSP.i want to insert data into database and also want to display... the following link: http://www.roseindia.net/jsp/displaydatafrom_database1.shtml
Dynamic retrieval od data from database and display it in the table at jsp
the data from the mysql database... pls its urgent.. help me frnds....   Here is a jsp code that retrieves the data from the database and display...Dynamic retrieval od data from database and display it in the table at jsp 
Display Data from Database in JSP
Display Data from Database in JSP   ... and execute query to display data from the specified table.  Before.... This is first jsp page that has a link 'show data from table', user can show
display date to jsp from database
display date to jsp from database   display date to jsp from database to calender if the start date and end date is available than calender date... not available in database field than show in green color and clickable. NOTE :- Date
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
jfreechart display from access database data.
jfreechart display from access database data.  I have made a database... to retrieve the data from the access database using prepared statement and then display the bar graph using jfreechart API .This whole retrieval and display of chart
How to display data from database in a TableView
How to display data from database in a TableView  I need to populate a TableView (JavaFx) with database items. I designed the TableView in JavaFx... at this. The classes: This is the Class that creates the database data object: import
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program
simple web appllication to insert, update or display from database - JSP-Servlet
in which we can insert, update or delete data from database. i can also display database content on jsp page. please send complete code. thank you mani saurabh...simple web appllication to insert, update or display from database  
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page ... the data from this .properties file and display it in table format. Ex:by using... = DEDCHGG_PWDP and goes on... I have to create a jsp page to show these data
How to display image in jsp from database using Servlet?
How to display image in jsp from database using Servlet?  Hi, How to display image in jsp from database using Servlet? Thanks   Hi, You will find code and example program at Retrieve image from database using Servlet
display data from database in textbox when id entered in textbox
display data from database in textbox when id entered in textbox  i wanted to enter data in textbox .depending on entered data in textbox data from database should be displayed dynamically in textbox
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how... the values from database based on the bookname or authorname entered must be display
Retrieve image from database using servlet and display in JSP
Retrieve image from database using servlet and display in JSP  Hi, I... to use MySQL Database from JSP page. How to retrieve image from database using servlet and display in JSP? Thanks
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
retrieving newly added records from mssql database and display in a jsp
retrieving newly added records from mssql database and display in a jsp ... from mssql database table and display those records in a jsp.And i have to delete... from the table and display in jsp and so on.This should be done forever(here we
Display Data from Database in JSF Application
Display Data from Database in JSF Application  ... data from database in JSF application. Developing JSF  Application In this section, we are going to display data from database in JSF based web
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page should display username, emailid, telephone in addition to tthe tagline however... sql = "select billid, customerid, billdate, status from customerbills where
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE  pls help me....in this i want to search books from the database... the user specified $data = mysql_query("SELECT * FROM book WHERE upper($field
Select Employee and display data from access database in a jtable
Select Employee and display data from access database in a jtable  I... server, and implement the needed data objects in a database server. The clients... a employee's name from a comboBox and the jtable will be filled with all
how to get data from database into dropdownlist in jsp
tutorial go through the link JSP Get Data Into Dropdown list From Database   ...how to get data from database into dropdownlist in jsp  Can anybody tell me what is the problem in this code as i am not able to fetch the data from
dynamic retrivel of data from mysql database in table format at jsp
the data from database and display it as table format in jsp... For example, i have...dynamic retrivel of data from mysql database in table format at jsp  ... of A1 should be retrived from database and display it in the respective textbox
data retrival from database throw simple jsp..
data retrival from database throw simple jsp..  We can retrieve the the data from data base simple jsp page: Jsp Page:retrive.jsp <...; Statement stmt = null; String Query="SELECT * FROM STUD"; try
JSP Get Data From Database
JSP Get Data From Database In this section we will discuss about how to get data from database using JSP. To get data from database to a JSP page we... giving a simple example which lets you understand to fetch data from database
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  //Customer Name: <select name="name"> <% try{ Class.forName...="select * from staff"; ResultSet rs=st.executeQuery(sql); while(rs.next
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <... searchProduct(SearchDTO sdto) { String query="select * from product
to display single row from database and next to display other question - JSP-Servlet
to display single row from database and next to display other question  Hi all, I am using JSP with MYSQL backend. In my project we have 100 questions in database we have to display first question on clicking the button
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Customer Name:<select name="name"> <% try{ Class.forName...=con.createStatement(); String sql="select * from staff"; ResultSet rs
How to Retrieve data from database in jsp
How to Retrieve data from database in jsp In this section we will discuss about how to fetch data from database table. We will give a simple example which will demonstrate you about fetching data from database table. Example We
design chart takes data from database and through jsp page
design chart takes data from database and through jsp page  how can I design chart takes data from database and through in jsp page
how to get the data from database&how to display the database data in jsf - Java Server Faces Questions
how to get the data from database&how to display the database data in jsf  Hi, 1.how to get the data from database. 2.how to display the database... and to display the data from database in jsf visit to : http://www.roseindia.net/jsf
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...(); System.out.println("Disconnected from database"); } catch (Exception e...://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="sql" uri="http://java.sun.com

Ads