Advanced Java Project – Mobile Search Page

Program 1

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
    <center>
        <font color="red" size="7">Mobile Search Page</font>
        <form method="post">
            <textarea name="txtmobile" rows="2" cols="150"></textarea>
            <br>
            <input type="submit" value="Search">
        </form>   
        
    </center>
    </body>
</html>

Program 2

<%-- 
    Document   : MobileSearch
    Created on : Dec 7, 2023, 4:23:04 PM
    Author     : admin
--%>

<%@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>
    </head>
    <body>
      <center>
        <font color="red" size="7">Mobile Search Page</font>
        <form method="post">
            <textarea name="txtmobile" rows="2" cols="150"></textarea>
            <br>
            <input type="submit" value="Search">
        </form>   
        <% 
             String mname=null;
             mname=request.getParameter("txtmobile");
             if(mname!=null)
             {
                 Connection con=null;
                 PreparedStatement ps=null;
                 ResultSet rs=null;
                 int flag=0;
                Class.forName("com.mysql.jdbc.Driver");
                //out.println("Driver load success.....");
                con=DriverManager.getConnection("jdbc:mysql://localhost/dataflair", "root", "root@data");
              //  out.println("Database Connection success.....");
                String sql;
                sql="select * from mobile where mbname like '"+mname+"%'";
                ps=con.prepareStatement(sql);
                rs=ps.executeQuery();
              
            
                out.println("<table border=1>");
                out.println("<tr><th>Mobile Id</th><th>Mobile Name</th><th>Price</th><th>Type</th></tr>");
                
                while(rs.next())
                {
                    flag=1;
                    out.println("<tr>");
                    out.println("<td>"+rs.getInt(1)+"</td>");
                    out.println("<td>"+rs.getString(2)+"</td>");
                    out.println("<td>"+rs.getInt(3)+"</td>");
                    out.println("<td>"+rs.getString(4)+"</td>");
                    out.println("</tr>");
                }
               out.println("<table>");
               if(flag==0)
                  out.println("<font color=blue size=7>No Mobile Found</font>");
             }    
        %>
    </center>
    </body>
</html>
courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *