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:
data are not display in JSP from database - JSP-Servletdata 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 databasehow 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
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
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 TableViewHow 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 values from database into table using jsphow 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 Display Data from Database in JSF ApplicationDisplay 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
displaying data retrieved from a database in a jsp pagedisplaying
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 databasejsp 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 databasejsp 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 databasejsp 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.
<
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 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 DatabaseJSP 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 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
How to Retrieve data from database in jspHow 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