2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by peter_budo
0
<%@ page language="java" import="java.util.*,java.sql.*,java.text.*;"%>
<%
  
  String user = "raja";
  String account_no = request.getParameter("accountno");
   String cashType = request.getParameter("cashType");
   int amount = Integer.parseInt(request.getParameter("amount").toString());
   int netamount=0;
  //out.println(user);
  // out.println(account_no);
   //.println(cashType);
   //out.println(amount);
   //out.println(cashdate);
  	   
    try {
         Class.forName("net.sourceforge.jtds.jdbc.Driver");
         Connection conn=DriverManager.getConnection("jdbc:jtds:sqlserver://SERVER:1433/banking","USER","PASSWORD"); 
         Statement st=conn.createStatement();
      
	  String strQuery = "select count(*),netamount from transaction where username='"+user+"' and accountno='"+account_no+"' and id=(select max(id) from transaction) group by id"; 
	  out.println("1" +strQuery);
	  ResultSet rs = st.executeQuery(strQuery);
	  out.println("Welcome");
	   if(rs.next())
		{
		    out.println("in select");
		   if(cashType.equals("Deposit"))
			{
              netamount = amount +  rs.getInt(2);    
			}
			else if(cashType.equals("WithDrawn"))
			{
				if(rs.getInt(2)>amount){
                 netamount = rs.getInt(2)-amount; 
				}
				else
				{
					 response.sendRedirect("cash.jsp?errmsg=error");
				}
			}
			strQuery = "insert into transaction  accountno='"+account_no+"',username='"+user+"',amount='"+amount+"',cashType='"+cashType+"',netamount='"+netamount+"'";
             int i = st.executeUpdate(strQuery);
			 if(i>0)
			{
				  response.sendRedirect("cash.jsp");
			}
			
		}
		else
		{
			netamount = amount;
		  	strQuery = "insert into transaction set accountno='"+account_no+"',username='"+user+"',amount='"+amount+"',cashType='"+cashType+"',netamount='"+netamount+"'";
			out.println("2 "+strQuery);
			 int i = st.executeUpdate(strQuery);
			 if(i>0)
			{
				  response.sendRedirect("cash.jsp");
			}
		}
      System.out.println("Connected to the database");
      conn.close();
      System.out.println("Disconnected from database");
    } catch (Exception e) {
      e.printStackTrace();
    }
 %>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.