27/01/25 ---------- Q)Java application to implement the use-case of balance enquiry. import java.sql.*; import java.util.Scanner; class BalanceEnquiryApplication{ public static void main(String[] args) throws SQLException{ Scanner scanner=new Scanner(System.in); System.out.print("Enter the A/c No:"); int accno=scanner.nextInt(); Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ashokitdb","root","ashokit"); Statement statement=connection.createStatement(); ResultSet resultset=statement.executeQuery("SELECT BALANCE FROM ACCOUNT WHERE ACCNO="+accno); if(resultset.next()){ System.out.println("Balance is Rs."+resultset.getDouble(1)); } else{ System.out.println("A/c doesn't exist"); } resultset.close(); statement.close(); connection.close(); scanner.close(); } } Q)Why to close the connection? =>to release the network resource of the JDBC client (client socket) maintained by database server, we must close the database connection. Q)Why to close Statement? to release the JDBC resource of the JDBC client at the database server side, we need to close the Statement. Q)Why to close ResultSet? =>to release the cached data of the client maintained at database server side, ResultSet should be closeed. Q)What happens within the DBMS when a SQL statement is submitted to it? 1)Query compilation 2)Query plan generation 3)Query execution Q)What is the limitation of Statement? =>Whenever, same SQL statement is required to be submitted repeatedly to the DBMS(of course with different data), we should not use Statement object as it compromises performance. Q)How to overcome the limitation of Statement? =>by using PreparedStatement which is the child of Statement.