Java

JDBC Batch Processing

This tutorial will teach you how to make a Batch Processing JDBC Gui application. In this example we are doing Account to Account transaction. have to sent the money from one account to another. This example will help you to  learn the process of Batch Processing and transaction statements.

First Step we have to find the account Holder Balance so enter the relavent account holder no to find them. i wrote the code below.

Complete Banking Management System  Click here  to watch them.

Paste the code inside the Find Button.

String accno = fano.getText();

try
 {
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection("jdbc:mysql://localhost/sanbank","root","");
      pst = con.prepareStatement("select balance from customer,account where customer.cust_id = account.cust_id and account.acc_id = ?");
      pst.setString(1, accno);
      ResultSet rs1 = pst.executeQuery();

     if(rs1.next() == false)
       {
         JOptionPane.showMessageDialog(null,"Account No no found");

        }

      else
        {
            String balance = rs1.getString(1);
            txtbal.setText(balance.trim());
        }

       } 
        catch(ClassNotFoundException ex) 
        {
          ex.printStackTrace();
        } 
        catch (SQLException ex) 
        {
           ex.printStackTrace();
        }

Paste the code inside the Tranfer Button.

 try {
       String faccno=  fano.getText( );
       String taccno= toano.getText( );

       int balance= Integer.parseInt( txtbal.getText( ));
       int amount =Integer.parseInt( txtamount.getText( ));

       Class.forName("com.mysql.jdbc.Driver");
       con = DriverManager.getConnection("jdbc:mysql://localhost/sanbank","root","");
       con.setAutoCommit(false);
            
       Statement st1=con.createStatement( );  
  
       String SQL1="update account set balance=balance- '" + amount  + "' where acc_id= '" + faccno  + "' ";

       String SQL2="update account set balance=balance+ '" + amount  + "' where acc_id= '" + taccno  + "'  ";

       String SQL3="insert into transfer(f_account,to_account,amount) values('" + faccno  + "','" + taccno  + "','" + amount  + "') ";

       st1.addBatch(SQL1);
       st1.addBatch(SQL2);
       st1.addBatch(SQL3);

 int[ ] status= st1.executeBatch( );

 for(int i=0;i<status.length;i++)
 {
          System.out.println( status[ i ] );
                     
        }
          JOptionPane.showMessageDialog(this, "Amount Transfer...!!!!!!!");
            fano.setText("");
            toano.setText("");
            txtamount.setText("");
            txtbal.setText("");

            con.commit();

        } 
        catch (ClassNotFoundException ex) 
        {
            ex.printStackTrace();
        }
        catch (SQLException ex) {

          ex.printStackTrace();
        }

I have attached the video tutorial below it will help you  to do this  step by step.

 

admin

Recent Posts

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

1 week ago

Java Payroll System Calculate Employee Overtime

Act as a Java developer to create a program that calculates the gross wage for…

2 weeks ago

Employee Working Hours Calculation System using Java

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

2 weeks ago

Laravel 11 School Management System

In this tutorial, we will teach you how to create a simple school management system…

2 weeks ago

How to Make Admin Panel Using React MUI

I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…

4 weeks ago

Install Laravel Breeze for Authentication Using Laravel 11

In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…

1 month ago