data are not display in JSP from database

Ads
 

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

Ads









Related Tutorials/Questions & Answers:
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
Advertisements
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 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
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
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 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
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
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 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. <
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
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

Ads