29/01/25 ---------- Calling a Stored Procedure in a Java application ------------------------------------------------------ Q)What is a stored procedure? =>A stored procdure is similar to a Java method. =>A stored procedure is a group of SQL statements when executed performs a specific task. =>A stored procedure is meant for processing of data within the database. Q)How to call a stored Procedure in a Java application? =>By using java.sql.CallableStatement object which is a child of PreparedStatement. Q)How to make use of a CallableStatement in a Java application? DIAGRAM Q)Java applcation that calls a stored procedure. import java.sql.*; class StoredProcedureApplication { public static void main(String[] args) throws Exception { Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ashokitdb","root","ashokit"); CallableStatement cst=con.prepareCall("{call addinterest(?,?)}"); cst.registerOutParameter(2,Types.FLOAT); cst.setInt(1,10001); cst.execute();//stored procedure is called float newbal=cst.getFloat(2); System.out.println("After adding interest, new balance is Rs."+newbal); cst.close(); con.close(); } } Q)What are the drawbacks of DriverManager? =>DriverManager has the following limitations 1)performance compromise in providing database connections to Java application 2)Not cost effective. 3)providing the connection is not secure.