JSP and JDBC

jdbc file:


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

<%
String accountNo= request.getParameter("accountno");

if (accountNo==null)
{
%>

<html>
<head>
<title>Enter the account no!</title>
</head>
<body>
    <form method="get" action="/index.jsp">
        <h1>Welcome to account transcation section.</h1>
        <h3>
            Account no:<input type="text" name="accountno" />
        </h3>
        <br /> <input type="submit" name="submit" />
    </form>
</body>
</html>

<%
}
else
{
    Double totalCredits=0.0;
    Double totalDebits=0.0;
    String name="name";
    Statement s;
    Connection con;
    ResultSet rs;
    String url="jdbc:odbc:transcation";
    Class.forName("jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection(url,"","");
    s=con.createStatement();
    String querry="SELECT * FROM Trans";
    rs=s.executeQuery(querry);
   
    while(rs.next())
    {
       
       
    int number= rs.getInt(2);
   
    if ((number==Integer.parseInt(accountNo)))
    {
        name=rs.getString(3);
        if (rs.getInt(5)==1)
        {
            totalCredits=totalCredits+rs.getInt(4);
        }
        else
        {
            totalDebits=totalDebits+rs.getInt(4);
        }
       
    }
    }   
%>
<html>
<head>
<title>Enter the account no!</title>
</head>
<body>

    <h1>Welcome to account transcation section.</h1>
    <h1>
        the paresed int for account no is
        <%= Integer.parseInt(accountNo)%></h1>
    <h1>
        Name=
        <%= name %></h1>
    <h1>
        Current Balance =<%out.print( totalCredits-totalDebits);%>
    </h1>
    <h1>
        Total Credits =<% out.print( totalCredits) ;%>
    </h1>
    <h1>
        Total Debits =<% out.print( totalDebits) ;%>
    </h1>

</body>
</html>
<%    
}
%>

No comments:

Post a Comment