Jsp

Jsp Mysql Search Records

This tutorial will teach you how to make search using Jsp mysql step by step.we have created the file index.jsp

Paste the code inside the index.jsp.after run the page you will see the above sceenshot page. when the page is load all data will be retrieved from the database. you have to enter the employee id on the text filed click submit button data will be retrieved from database according the text you entered.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    </head>
    <body>
        <div class="container">
            <div class="form-group col-12 p-0">
             <%
                Connection con;
                PreparedStatement pst;
                ResultSet rs;
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection("jdbc:mysql://localhost/mcompany","root","");
                String empid = request.getParameter("empid");
                 out.print("<h3>Employee Details</h3>");
                if (empid == null || empid.isEmpty()) 
                {
                  pst = con.prepareStatement("select * from employee");
                  rs = pst.executeQuery();
                   
                 while(rs.next())
                 {    
                     out.print("<Table border=1 bgcolor=yellow cellpadding=2 cellspacing=2>");
                     out.print("<TR>");
                     out.print("<TD>" + rs.getString("name") + "<TD>");
                     out.print("<TD>" + rs.getString("phone") + "<TD>");
                     out.print("<TD>" + rs.getString("salary") + "<TD>");
                     out.print("</TR>");
                      out.print("</Table>");
                 }  
                }
               else {
                pst = con.prepareStatement("select * from employee where id =?");
                pst.setString(1, empid);
                rs = pst.executeQuery();
                 while(rs.next())
                 {   
                     out.print("<Table border=1 bgcolor=yellow>");
                     out.print("<TR>");
                     out.print("<TD>" + rs.getString("name") + "<TD>");
                     out.print("<TD>" + rs.getString("phone") + "<TD>");
                     out.print("<TD>" + rs.getString("salary") + "<TD>");
                     out.print("</TR>");
                      out.print("</Table>");
                 }
                }
              %>                   
  <body>
        <div class="container">
             <div class="form-group col-6 p-0">
                 <form id="form" method="post" action="index.jsp" class="form-horizontal">
                       <div class="form-group col-md-6"> 
                           <label>Employee ID</label>
         <input type="text" name="empid" class="form-control" id="empid" placeholder="Employee ID">
                        </div>
                      <div class="form-group col-md-6" align="center"> 

                        <Button class="btn btn-success" style="width: 80px;">Submit</Button>
              
                        </div>
                     
                 </form>
                 
             </div>
         </div>   
    </body>
</html>

I have attached the video tutorial below it will help you  to do this  step by step.

 

admin

Recent Posts

ChatGPT Free Online Download the ChatGPT App Easily

Have you ever wanted to talk to a friendly, smart robot that helps you with…

3 days ago

Free GPT Chat? DeepSeek AI Does It Better

DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…

2 weeks ago

Spring Boot MySQL Complete CRUD REST API [ Free Sourecode ]

Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…

2 weeks ago

CREATE Responsive Navigation Bar with FlexBox CSS!

Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…

4 weeks ago

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 months ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

3 months ago