27 Jun 2014

Online Money Transfer Application using Java

/*
In DATABASE:
Create a table :create table account(toacc varchar2(10),tobal number,fromacc varchar2(10),frombal number);
Insert a row: insert into account values('SBI123',50000,'AND123',50000);
Then start the application
*/

import java.sql.*;
import java.util.*;
class Transaction 
{
 public static void main(String[] args) throws ClassNotFoundException 
 {
  try
  {
   int x,toamt,fromamt,g,h;
   String fromacc,tacc;
   Class.forName("oracle.jdbc.OracleDriver");
   System.out.println("Driver loaded");
   Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
   System.out.println("Connection established");
   Statement stmt=con.createStatement();
   ResultSet rs=stmt.executeQuery("select * from account");
   Scanner s=new Scanner(System.in);
   rs.next();
   System.out.println("Enter your account number");
   tacc=s.nextLine();
   System.out.println("Enter transfer amount");
   fromamt=Integer.parseInt(s.nextLine());
   System.out.println("Enter account number to whom you want to transfer");
   fromacc=s.nextLine();
   if(rs.getString(1).equals(tacc) && rs.getString(3).equals(fromacc))
   {
    if(rs.getInt(4)>(fromamt+500))
    {
     System.out.println("Welcome Hemanth Kumar Tanguturi");
     int k=rs.getInt(2)+fromamt;
     int l=rs.getInt(4)-fromamt;
     PreparedStatement pstmt=con.prepareStatement("update account set tobal=?,frombal=? where toacc=?");
     pstmt.setInt(1,l);
     pstmt.setInt(2,k);
     pstmt.setString(3,tacc);
     pstmt.executeUpdate();
     System.out.println("Account number of Hemanth Kumar Tanguturi is reduced to"+l);
     System.out.println("Account number of Sreekanth Tanguturi enhanced to"+k);
     System.out.println("Amount Transfered successfully\nThank U for Transaction");
    }
 
     else
     {
      System.out.println("Account should have minimum balance");
     }
    }
    else
    {
     System.out.println("Account numbers not matched");
    }
  }
  catch (SQLException e)
  {
   System.out.println("There is slight problem in transaction try again"+e);
  }
  
   }
}



/*
output 1:

Driver loaded
Connection established
Enter your account number
SBI123
Enter transfer amount
5100
Enter account number to whom you want to transfer
AND123
Welcome Hemanth Kumar Tanguturi
Account number of Hemanth Kumar Tanguturi is reduced to44900
Account number of Sreekanth Tanguturi enhanced to55100
Amount Transfered successfully
Thank U for Transaction

output 2:

Driver loaded
Connection established
Enter your account number
SBI123
Enter transfer amount
600000
Enter account number to whom you want to transfer
AND123
Account should have minimum balance

*/

No comments:

Post a Comment