Sunday, March 7, 2021

Java JSP program to display account holder's details in a bank having a balance greater than 50,000/-

 //JSP file

<%-- 

    Document   : Bankjsp

    Created on : 19 Mar, 2020, 12:04:04 PM

    Author     : ashu

--%>

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

<%@ page import="javax.servlet.http.*,javax.servlet.*" %>

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

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

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

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

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

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

<%@ page language="java"%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

    <head>

        <title>Real Bank JSP Page</title>

    </head>

    <body>

    <center>

        <h1>Welcome to Real Bank!</h1>

        <h3>Customers with balance greater than Rs.5000/- in SB a/c </h3>

        

        <%

            try {

            String connectionURL = "jdbc:mysql://localhost/bank";

            Class.forName("com.mysql.jdbc.Driver").newInstance(); 

            Connection con = DriverManager.getConnection(connectionURL, "root", "ashutosh");

            if(con.isClosed()){

                 out.println("Successfully connected to " + "MySQL server using TCP/IP...");

            }

            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery("select customerName, customerAddress, accountNum from customers where accountType='SB' and balance >= 5000.00;");

            %>

            <table border=1>

            <tr><th>Name</th><th>Address</th><th>Account Number</th></tr>

            <%

            while(rs.next()){

            %>

            <tr>

            <td><%=rs.getString(1)%></td>

            <td><%=rs.getString(2)%></td>

            <td><%=rs.getInt(3)%></td>

            </tr>

        <%   

        }

        rs.close();

        stmt.close();

        con.close();

        }catch(Exception ex){

            out.println("Unable to connect to database"+ex);

        }   

        %>

        

    </center>

    </body>

</html>

---------------------------------------------------------------------------------------------------

//Corresponding HTML file

<!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>Real Bank</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
    <center><h1>Welcome to Real Bank!</h1>
        <h2>You can bank with us for best returns and services</h2>
    <div><a href="Bank.jsp">Details of customers having greater than equal to Rs.5000/- in savings account</a></div>
    </center>
        
    </body>
</html>

----------------------------------------------------------------------------------------------------


No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows