Home Answers Viewqa JavaScriptQuestions how to display data from database according to entered value in search field

 
 


ena
how to display data from database according to entered value in search field
1 Answer(s)      a year ago
Posted in : JavaScript Questions

this is my search.jsp file

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%@page import="java.sql.*"%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Healthy Preggers</title>
<meta name="keywords" content="css templates, healthy living, diet, nutrition, fitness, web design" />
<meta name="description" content="Healthy Living - free CSS template provided by templatemo.com" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
    color: #999999
}
.style2 {color: #BF3E3E}
-->
</style>
</head>
<body>
<%@include file = "header.jsp" %>
<%@include file = "menu.jsp" %>


<%   Class.forName("oracle.jdbc.OracleDriver");
     Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "health", "health"); 
       %> 
<body>

<html>
<head>
</head>
<body>
<br><br><br><br><br><br>
<form method="post" name="form1" action="viewsearch.jsp">
<table border="1" width="300" align="center" bgcolor="FFA3B3">
<tr><td colspan=2 style="font-size:12pt;color:#00000;" align="center">
<h3>Enter BMI Value</h3></td></tr>
<tr><td ><b>Enter BMI </b></td>
<td>: <input  type="text" name="bmi_value" id="BMI_VALUE">
</td></tr>

<tr><td colspan=2 align="center">
<input  type="submit" name="submit" value="Search">  
                        <input type="reset" value="Reset" name="Reset" /></td></tr>
</table>
</form>


</body>
</html>

</table>
</form>
</body>
</html>
<br><br><br>

<div id="templatemo_footer">
    Copyright © 2012| 
    Designed by:Fara Zati Aina</a> | 
    For: CSC 444</div> 
</center></body>
</html>



this is my searchview.jsp file where it does the process

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%@page import="java.sql.*"%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Healthy Preggers</title>
<meta name="keywords" content="css templates, healthy living, diet, nutrition, fitness, web design" />
<meta name="description" content="Healthy Living - free CSS template provided by templatemo.com" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
    color: #999999
}
.style2 {color: #BF3E3E}
-->
</style>
</head>
<body>
<%@include file = "header.jsp" %>
<%@include file = "menu.jsp" %>


<%   Class.forName("oracle.jdbc.OracleDriver");
     Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "health", "health"); 
       %> 
<body>

<html>
<head>
</head>
<body>
<br><br><br><br><br><br>
<form method="post" name="form1" action="viewsearch.jsp">
<table border="1" width="300" align="center" bgcolor="FFA3B3">
<tr><td colspan=2 style="font-size:12pt;color:#00000;" align="center">
<h3>Enter BMI Value</h3></td></tr>
<tr><td ><b>Enter BMI </b></td>
<td>: <input  type="text" name="bmi_value" id="BMI_VALUE">
</td></tr>

<tr><td colspan=2 align="center">
<input  type="submit" name="submit" value="Search">  
                        <input type="reset" value="Reset" name="Reset" /></td></tr>
</table>
</form>


</body>
</html>

</table>
</form>
</body>
</html>
<br><br><br>

<div id="templatemo_footer">
    Copyright © 2012| 
    Designed by:Fara Zati Aina</a> | 
    For: CSC 444</div> 
</center></body>
</html>



this is my searchview2.jsp file where it display the result


<%-- 
    Document   : viewSearch2
    Created on : Jun 18, 2012, 8:21:02 PM
    Author     : Asus
--%>


<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%@page import="java.sql.*"%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Healthy Preggers</title>
<meta name="keywords" content="css templates, healthy living, diet, nutrition, fitness, web design" />
<meta name="description" content="Healthy Living - free CSS template provided by templatemo.com" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
    color: #999999
}
.style2 {color: #BF3E3E}
-->
</style>
</head>
<body>
<%@include file = "header.jsp" %>
<%@include file = "menu.jsp" %>


<%   Class.forName("oracle.jdbc.OracleDriver");
     Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "health", "health"); 
       %> 
<body>
<html>
    <body>
<h1 align="left">VIEW SEARCH</h1>



                <%
                 Statement st=con.createStatement();
                 ResultSet rs3=st.executeQuery("SELECT M.MEMBER_ID, M.FNAME,M.LNAME,M.AGE,B.HEIGHT,B.WEIGHT, B.BMI_VALUE FROM MEMBER M , BMI B   WHERE M.MEMBER_ID=B.MEMBER_ID");
                %>
                    <table  align="center"  border="1">

                    <tr  bgcolor="ACFA58"> 
                           <th class="listingContent" witdth="10">No</th>
                          <th class="listingContent" width="100">ID</th>
                          <th class="listingContent" width="1000">FIRST NAME</th>
                          <th class="listingContent" width="1000">LASTNAME</th>
                          <th class="listingContent" width="1000">AGE</th>
                          <th class="listingContent" width="1000">HEIGHT</th>
                          <th class="listingContent" width="1000">WEIGHT</th>
                          <th class="listingContent" width="300">BMI VALUE</th>

                    </tr>


             <% String data=request.getParameter("bmi_value"); 
             if(data != "bmi_value"){ %>

             <script language="javascript">
             alert("There is no data.");
             window.location.href = "searchBMI.jsp";
             </script> 
            <% } 
          else{

    %>  <%
            int y= 1;
            while(rs3.next())
              { %>

                <tr bgcolor="D0F5A9"  onclick="form1">
                <td class="listingContent" align="center"><%= y%></td>
                <td class="listingContent" width="10" align="center"><%= rs3.getString("member_id") %></td>
               <td class="listingContent" width="10" align="center"><%= rs3.getString("fname") %></td>
               <td class="listingContent" width="10" align="center"><%= rs3.getString("lname")%></td>
               <td class="listingContent" width="10" align="center"><%= rs3.getString("age")%></td>
               <td class="listingContent" width="10" align="center"><%= rs3.getString("height")%></td>
               <td class="listingContent" width="10" align="center"><%= rs3.getString("weight")%></td>
               <td class="listingContent" width="10" align="center"><%= rs3.getString("bmi_value")%></td>
                </tr> 

                <% 
                y++;
                }%>
                   } </table>

    </body>
</html>


i suppose to get this table, but it shows wrong value .i want it to be the same with what i have entered in the search field. let say i entered 17, so i want the data of user who have 17 as their bmi value to appear. help me please. i don't know which line i have to add or change my code. thank you :)
View Answers

June 20, 2012 at 4:00 PM


Here is a simple JSP search application where user is allowed to enter BMI value and display the results accordingly.

1)search.jsp:

<html>
<head>
</head>
<body>
<br><br><br><br><br><br>
<form method="post" name="frm" action="..//search">
<table border="0" width="300" align="center" bgcolor="#CDFFFF">
<tr><td colspan=2 style="font-size:12pt;color:#00000;" align="center">
<h3>Search Form</h3></td></tr>
<tr><td ><b>Enter BMI</b></td>
<td>: <input type="text" name="bmi" id="bmi">
</td></tr>
<tr><td colspan=2 align="center">
<input type="submit" name="submit" value="Search"></td></tr>
</table>
</form>
</body>
</html>

2) Search.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import java.util.*;

public class Search extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";


Statement st;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
String bmi = request.getParameter("bmi");
String query = "select * from item where bmi='"+bmi+"'";
st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
out.println("<table border='1'><tr><th>Member ID</th><th>First Name</th><th>Last Name</th><th>Age</th><th>BMI Value</th></tr>");
while(rs.next()){

out.println("<tr><td>"+rs.getString(1)+"</td><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+"</td></tr>");
}
out.println("</table>");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}

3)web.xml:

<servlet-name>Search</servlet-name>
<servlet-class>Search</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Search</servlet-name>
<url-pattern>/search</url-pattern>
</servlet-mapping>









Related Pages:
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... it to be the same with what i have entered in the search field. let say i entered 17...; <input type="submit" name="submit" value="Search">
Search data from database - Java Beginners
to user name. (means search all field from database and display using...Search data from database  Hi Deepak, This is not correct code... in the previous page, then according to that, use the sql command as delete * from
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... Solution field from database and display in the textbox of the jsp.   1... * from item where itemid='"+id+"'"); while(rs.next()) { data = ":" + rs.getString
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
how to know which jList is selected and according to that fetch the value
from database (i successfully did it already) there are many field in tabs ( i.e... is selected) to fetch data from database using selected employee id from selected...how to know which jList is selected and according to that fetch the value 
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
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
How to collect Java input field value display into Jtable?
How to collect Java input field value display into Jtable?  <p>We would like to know how to collection input field data into Jtable... as the following information. - display the value in the JTable. If in the GUI as per view
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... where i have to show the search result in the same panel of where search field... next search value in the textfield it makes another set of columns
I have to retrieve these data from the field table
I have to retrieve these data from the field table  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from
JTable Display Data From MySQL Database
JTable Display Data From MySQL Database In this section we will discuss about how to display data of a database table into javax.swing.JTable This section... on the search button. We will display the fetched data into a table which is added
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 show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database... .when i enter search value in the search field only one row is displayed
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database... .when i enter search value in the search field only one row is displayed
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database... .when i enter search value in the search field only one row is displayed
how to display data in excel sheet?
how to display data in excel sheet?  According to the user Id,some links will be generated from the database,and if we click a link,data would be retrieved from the database and data will be displayed in a new page.in this page
how to display the data from excel to webpage
how to display the data from excel to webpage  Hi, I need help on following I have a webpage contains a text box and a button(get), i give a value... search for the value 4024 in a excel file and to display the remaining values
Search from Database In Servlet
Search from Database In Servlet   ... the database according to the Search text. viewSearch.jsp display the search data from database on the browser.  Step 1: Create a web page
Display Data from Database in JSP
; <html> <head> <title>display data from...;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
use data from database table as hyperlink value - JSP-Servlet
use data from database table as hyperlink value  I'm creating a web page that allows user to search my database. The page will display partial... to hyperlink. I want to use this data as hyperlink and use it as the value
retrieve record from the field table
retrieve record from the field table  Hi. I have a field in database...,kanchipuram for a single record. I have to retrieve these data from the field table... values like chennai as one value, trichy as one value. and i have to show it in html
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 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 a value in combobox.   I have the same problem.plz help me. I have MySQL... have to display the Nodename and packageno. i.e.,select nodename,packageno from
MySql Databse query to fetch results from database and display it in HTML File
MySql Databse query to fetch results from database and display it in HTML File  Hi. I have a field in database named stages. its datatype is varchar... to retrieve these data from the field table. Actually they are separated by comma
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text... are stored in database wherein when the in the first text field the data is already... from database and entered the next page should load without the user clicking
Display data
Display data  after successful login how i can fetch my account information from sql database
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... is to be done in a servlet.. Note that it is a access made database. How can I
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... database based on the bookname or authorname entered must be display as view.  
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.... one.jsp value of 'school' request parameter are comming from the link
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
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..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id
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..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id
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..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id
to store data entered in html page
to store data entered in html page  i want to a job site... use two forms for it 1)for user name,password, submit button 2)for text field... submit we have to move to form 2 on there we have enter text data
Inserting a value to an Enum field in Table
as a 'N' but I get some database error that says data truncated. How do I set...Inserting a value to an Enum field in Table  I'm writing a code... database. For example, in the user table I have: username varchar(15) PRIMARY KEY
Code for search data - Development process
Code for search data  Hi, can u give me jsp code for search data. When i select any 1 from 3, it has to display all d corresponding data from database sub-combo box in this code is not working. Search Page
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?
how to display?  I have to write a code for searcing books in library...; </tr> <tr> <td> <input type="submit" value="Search" />.... search.html <body> <form name="search" action="http://localhost
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
retrive data from database?
retrive data from database?  hellow i have a database sheet name as db1. it's contain sixty(60) sn,name ,rollno(primary key),father's name etc... from db1 and enter value in text box according there name,rollno and save
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: http://roseindia.net/jsp/servlet-jsp-data-list.shtml Thanks
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am... rs=st.executeQuery("select * from data where id=1"); while(rs.next
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit...=conn.createStatement(); ResultSet rs=st.executeQuery("select * from data
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 things i have entered in the same page inside the corresponding fields
Fetching database field from servlet to jsp page ?
Fetching database field from servlet to jsp page ?  Hello Java... field. I wanted to pass some of the database field from servlet to jsp... (i am opening my database in servlet init() method ) how to pass rs.getString(8
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