I want to display values from database into table based on condition in query, how to display that? For example i have some number of books in database but i want to display books based on either bookname or authorname, for this i created one jsp page with fields bookname and authorname and search button and also action for that in jsp, if i enter either bookname or authorname and click on search button the values from database based on the bookname or authorname entered must be display as view.action must be written in jsp only
I tried but didnt get values.In servlets its working but not working in jsp
September 3, 2012 at 11:20 AM
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<script>
function change(){
var cid=document.getElementById("book").selectedIndex;
var val = document.getElementById("book").options[cid].text;
window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?id="+cid+"&&value="+val);
}
function extract(){
var ide=document.getElementById("info").selectedIndex;
var bookname = document.getElementById("info").options[ide].text;
window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?book="+bookname);
}
</script>
<%!
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";
%>
<%
String value=request.getParameter("value");
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
st = conn.createStatement();
rs = st.executeQuery("select * from book");
%>
<select id="book" onchange="change();">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value="<%=rs.getString("books")%>"><%=rs.getString("books")%></option>
<% if(rs.getString("books").equals(value)){%>
<option value="<%=value%>" selected disabled><%=value%></option>
<%
}
}
%>
</select>
<select id="info" onchange="extract(this)">
<option value="0">--Please Select--</option>
<%
String id=request.getParameter("id");
rs=st.executeQuery("select * from bookInformation where bookid='"+id+"'");
while(rs.next()){
%>
<option value="<%=rs.getString("id")%>" ><%=rs.getString("booknames")%></option>
<%
}
%>
</select>
<%
String book=request.getParameter("book");
String author="";
String price="";
rs=st.executeQuery("select * from bookInformation where booknames='"+book+"'");
while(rs.next()){
author=rs.getString("writer");
price=rs.getString("price");
}
if((book!=null)&&(author!=null)&&(price!=null)){
%>
<table >
<tr><td>Book Name</td><td><input type="text" value="<%=book%>"></td></tr>
<tr><td>Author</td><td><input type="text" value="<%=author%>"></td></tr>
<tr><td>Price</td><td><input type="text" value="<%=price%>"></td></tr>
</table>
<%
}
%>
</body>
</html>
For the above code, we have used following database tables:
1)book
CREATE TABLE `book` (
`bookid` bigint(20) NOT NULL auto_increment,
`books` varchar(255) default NULL,
PRIMARY KEY (`bookid`)
);
2)bookinformation
CREATE TABLE `bookinformation` (
`id` bigint(255) NOT NULL auto_increment,
`bookid` int(255) default NULL,
`booknames` varchar(255) default NULL,
`writer` varchar(255) default NULL,
`Price` double default NULL,
PRIMARY KEY (`id`)
);
For more information, visit the following link:
http://www.roseindia.net/jsp/searchbook.shtml
Related Tutorials/Questions & Answers:
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 how to display a table from database using servlethow to
display a
table from database using servlet
how to
display a
table with
values from servletpage
Hi Friend,
Please go through the following link:ADS_TO_REPLACE_1
http://roseindia.net/
jsp/servlet-
jsp-data
Advertisements
How to Display values from databse into tableHow to
Display values from databse into table I want to
display values from database into
table based on condition in query,
how to
display that?
For example i have some number of books in
database but i want to
display books
Display Blob(Image) from Mysql table using JSP Display Blob(Image)
from Mysql
table using JSP
In this section, we will
display blob data(image)
from Mysql
database table
using JSP code.
A Blob stores... Also :
Insert Blob(Image) in Mysql
table using JSP
Download Source CodeADS
edit values of database using jspedit
values of
database using jsp hi i want a code to edit the row
from tye
database and
display in a page which containd radio buttons and drop down boxes
using jsp code
edit values of database using jspedit
values of
database using jsp hi i want a code to edit the row
from tye
database and
display in a page which containd radio buttons and drop down boxes
using jsp code
how to create database and table using jsphow to create
database and
table using jsp hi frnds....,
i want to create
database and
table in mysql
using jsp.... i have an registration form(name...
table using jsp code... the
table name should be the name of the person
how to display data from jsp file into databasehow to
display data
from jsp file into database this is a
jsp file...(); in the below example. the error is "cannot convert
from java.sql.Statement...,emailId,phone1,phone2)
values('"+t+"','"+n+"','"+cn+"','"+pos+"','"+req+"','"+eid+"',"+ph1
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 in JSP;head>
<title>
display data
from the
table using jsp</title>
<...;To
display all the data
from the
table click here...</h2></TD>..., to show data
from the
database
click on the link that calls another .
jsp file named
how to display the database values in pdf format how to
display the
database values in pdf format in struts
how to
display the
values in pdf format when clicking a button in
jsp page
jsp code
using itext api:
<%@page import="java.io.*"%>
<%@page import
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
getting values from database - JSP-Servlet JSP code separately.If it will not
display database values then try your code...getting
values from database I tried the following code
abc.html
aaa.jsp
I am not getting exceptions now
Retrieve values from database using viewsRetrieve
values from database using views hi.........
I have a huge
database so i have created views in
database where i am selecting only...
from that created views and
display on form . I am trying to do so but its
Display Sum of Table Column Using In JSP Display Sum of
Table Column
Using In
JSP... the total salary
between two specific date and result is
display using Jsp... an application to
Display the sum data
of a
Table column for a specific Date. We
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 Display Data from Database in JSP Display Data
from Database
in
JSP
...;head>
<title>
display data
from the
table using jsp</title>
<...;
<head>
<title>
display data
from the
table using jsp</title>
how to display records from databasehow to
display records
from database I want to
display records
from database in tables, the
database is having 2000 records and i want to
display 20... as like next button
using classic asp i need codes for the above said process