//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>
No comments:
Post a Comment