24-01-25 ---------- Q)Dedevelop a JDBC Applicatimport java.sql.*;//making JDBC API available to the program class UpdateApplication{ public static void main(String[] args)throws SQLException{ Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ashokitdb","root","ashokit"); Statement statement=connection.createStatement(); int re=statement.executeUpdate("UPDATE ACCOUNT SET BALANCE=BALANCE+5000"); System.out.println(re+" rows effected"); statement.close(); connection.close(); } } ion that increases the balance of all the accounts by Rs.5000. UPDATE ACCOUNT SET BALANCE=BALANCE+5000 import java.sql.*;//making JDBC API available to the program class UpdateApplication{ public static void main(String[] args)throws SQLException{ Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ashokitdb","root","ashokit"); Statement statement=connection.createStatement(); int re=statement.executeUpdate("UPDATE ACCOUNT SET BALANCE=BALANCE+5000"); System.out.println(re+" rows effected"); statement.close(); connection.close(); } } Q)Develop a Java application to delete a specified account form the database table. //DeleteAccount.java import java.sql.*;//making JDBC API available to the program import java.util.Scanner; class DeleteApplication{ public static void main(String[] args)throws SQLException{ Scanner scanner=new Scanner(System.in); System.out.println("Enter the A/NO"); int n=scanner.nextInt(); Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ashokitdb","root","ashokit"); Statement statement=connection.createStatement(); int de=statement.executeUpdate("DELETE FROM ACCOUNT WHERE ACCNO="+n); if(de==0){ System.out.println("Account doesn't exist"); } else{ System.out.println("deleted sucessfully"); } statement.close(); connection.close(); scanner.close(); } } Q)How to read data from the database? =>By submitting SELECT statement to the DBMS, data is retrieved from the database. =>by using executeQuery() method on the statement object, SELECT STATEMENT IS submitted to the DBMS. ResultSet resultset=statement.executeQuery("SELECT ..."); Q)Explain about java.sql.ResultSet? =>Object oriented representation of database records is nothing but ResultSet object. =>ResultSet has the following structure. DIAGRAM =>When the ResultSet is open, a logical pointer known as cursor points to the ZERO recrod area. =>When the cursor is pointing to ZERO record area OR no record area,we should not retireve the column values =>to move the cursor we use "next()" method of ResultSet object. =>next() method does two things. 1)It moves the cursor by one record (area) in forward direction 2)It returns true if record exits otherwise false. =>to read the column values, getXXX() methods of the ResultSet are used. =>These methods take column number of the ResultSet record as argument and returns column value. For eg. int ano=resultset.getInt(1) String name=resultset.getString(2); double balance=resultset.getDouble(3); Q)Develop a JDBC application to retrieve all the accounts from the database and display their details. import java.sql.*;//making JDBC API available to the program class ReadApplication{ public static void main(String[] args)throws SQLException{ Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ashokitdb","root","ashokit"); Statement statement=connection.createStatement(); ResultSet resultset=statement.executeQuery("SELECT * FROM ACCOUNT"); System.out.println("ACCNO NAME BALANCE"); while(resultset.next()){ System.out.println(resultset.getInt(1)+" "+resultset.getString(2)+" "+resultset.getDouble(3)); } resultset.close(); statement.close(); connection.close(); } }