AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-jsp: Code for Banking balance for debit-credit amount in JAVA

plz suggest for how to write this is code banking debit+credit+balance+sdate
our required to follow just like any Bank Pass Book Format.

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<%@ page import="java.util.Calendar" %>

<%

//java Code
String date = (new java.util.Date()).toString();
String UserName = request.getParameter("UserName");
String CusId= request.getParameter("CusId");
String AccountNo = request.getParameter("AccountNo");
String Debit = request.getParameter("Debit");
String Credit=request.getParameter("Credit");
String Balance=request.getParameter("Balance");
String sDate=request.getParameter("sDate");
//String startDate=request.getParameter("startDate");


try
{
String s="jdbc:odbc:Database1";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(s);
Statement statement = conn.createStatement();
Calendar calendar = Calendar.getInstance();
java.sql.Date startDate = new java.sql.Date(calendar.getTime().getTime());

//String sqls="SELECT (SUM(debit)*-1) + SUM(credit) Balance FROM abcbank WHERE sDate BETWEEN CURDATE() AND ADDDATE(CURDATE() INTERVAL -30 DAY)";

String sql= "SELECT sDate ,(SUM(Debit)*-1) + SUM(Credit) Balance FROM abcbank GROUP BY sDate ";
ResultSet rst = statement.executeQuery(sql);
while (rst.next())
{
rst.getInt("Balance");
}

String update="UPDATE abcbank SET Balance =Balance +Debit WHERE Debit=? AND sDate ="+sDate+" ";
int updateSet = 0;
updateSet = statement.executeUpdate(update);

if (updateSet > 0)
{
System.out.println("An existing user was updated successfully!");
}
rst.close();
statement.close();
conn.close();
out.println("Data is update successfully !");
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
}

%>


Could you please correct the code and send correct code. As early as possible.


Thanking you.


java x 210
jsp x 32
Posted On : 2016-10-24 07:47:53.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
267150
up-rate
3
down-rate

Answers


well, first thing i´d like to suggest you to use transaction handling as it´s about money and we have to be very careful.

use like this
try{
.
.
.
.
conn.autoCommit(false);
String sql= "SELECT sDate , Balance FROM abcbank where custId=? GROUP BY sDate ";
ResultSet rst = statement.executeQuery(sql);
while (rst.next())
{
rst.getInt("Balance");
}

String update="UPDATE abcbank SET Balance =Balance -Debit+credit WHERE custId=? AND sDate ="+sDate+" ";
int updateSet = 0;
updateSet = statement.executeUpdate(update);

if (updateSet > 0)
{
conn.commit();
System.out.println("An existing user was updated successfully!");
}else{
conn.rollback();
System.out.println("Something Went Wrong!!");
}
}catch(Exception e){
conn.rollback();
e.printStackTrace();
}finally{
rst.close();
statement.close();
conn.close();
}

Posted On : 2016-10-24 23:08:02
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222642
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in