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 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

View Answers

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 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
how to display a table from database using servlet
how 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 all the Select values from the MySQL database table in where condition= In JSP?
How to display all the Select values from the MySQL database table in where... to display all the select values from MySQL DB** only first value is displayed in the jsp file. @select * from table dept where dept_no=10;" jsp code i have used
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
how to read values from excel sheet and compare with database using jsp
how to read values from excel sheet and compare with database using jsp  hi sir i am arun how to read values from excel sheet and compare with database using jsp coding i.e, if i have 6(assetid,assetname,serialno,cubical
How to Display values from databse into table
How 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
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes...; <pre class="prettyprint"> // sql query to retrieve values from
How to edit values in textboxes from database using jsp
How to edit values in textboxes from database using jsp  Hi RoseIndia... from database table using jsp, here is my code Please can anyone help me...(); System.out.println("Disconnected from database"); %>
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript
to display previous 10records. Database Query like this: Select * from table...How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript  when click on the next
Retrieve database from the table dynamically in jsp from oracle using servlet
Retrieve database from the table dynamically in jsp from oracle using servlet  Sir, I have created a table in oracle using eclipse, and added few... using java servlet from the database in the jsp page
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
Retrieve image from database using servlet and display in JSP
to use MySQL Database from JSP page. How to retrieve image from database using servlet and display in JSP? Thanks...Retrieve image from database using servlet and display in JSP  Hi, I
edit values of database using jsp
edit 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 jsp
edit 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
Dynamic retrieval od data from database and display it in the table at jsp
Dynamic retrieval od data from database and display it in the table at jsp ...; Here is a jsp code that retrieves the data from the database and display... the details of 20 members in a table format at jsp page by dynamically retrieving
how to create database and table using jsp
how 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 fetch entries/values from database to a jsp page one by one?
How to fetch entries/values from database to a jsp page one by one?  I have a table in Microsoft SQL server Management Studio with two columns title... to display different database entries of the each column in different blocks. Now
how to display data from jsp file into database
how 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
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
how to use String tokenizer on table that is retrieved from database using jsp servlet
how to use String tokenizer on table that is retrieved from database using jsp servlet  Query:Table---- mysql> select pid,medicinename,dose,day,qty from medicinedetails2 where pid=15
How to store values in a database using JSTL? - JSP-Servlet
How to store values in a database using JSTL?  I want to store values in a database... How can i store in database? Here is my code... This wil extract details and displays in a table format... Now i want to store these values
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
Retrive values from an arraylist and display in a jsp?
Retrive values from an arraylist and display in a jsp?  Hi, I need help in jsp to display values of an ArrayList in jsp. There is a java file...") != null) { Open connection to the database; Read parameters from
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
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file  Hi am new to java. i need to create... Solution field from database and display in the textbox of the jsp.   1
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
Retrive values from an arraylist and display in a jsp?
Retrive values from an arraylist and display in a jsp?  Hi, I need help in jsp to display values of an ArrayList in jsp. There is a java file...") != null) { Open connection to the database; Read parameters from
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
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  ... to insert all selected values in data base correspondent to each like if user selected india and then goa. I want to insert it to a table which has two fields
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
How to display data fom MySQL DataBase-table in to JSP file by submitting... DataBase/DB Name:lokesh; Table Name:TR_list; columns:nodename,packageno,TR... have to display the Nodename and packageno. i.e.,select nodename,packageno from
Retrieve values from database using views
Retrieve 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
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
How to Dragging and dropping HTML table row to another position(In Jsp... have one Html table in jsp page and i am iterating values (in columns of html table)from Database, Now i am Dragging and dropping one HTML table row to another
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
How to retrieve image from database using jsp and servlet?
How to retrieve image from database using jsp and servlet?  Hi, I am trying to find code for displaying the image from database in a JSP page. How to retrieve image from database using jsp and servlet
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
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
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
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 database
how 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
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

Ads