Illustration to call the capacity utilizing JDBC

In this illustration, we are calling the sum4 capacity that gets two info and returns the total of the given number. Here, we have utilized the registerOutParameter system for CallableStatement interface, that registers the yield parameter with its comparing sort. It gives data to the CallableStatement about the kind of result being shown.

The Types class characterizes numerous constants, for example, INTEGER, VARCHAR, FLOAT, DOUBLE, BLOB, CLOB and so forth.

 
open String getDriverVersion()throws SQLException: it gives back the rendition number of the JDBC driver. 

How about we make the basic capacity in the database first.


make or supplant capacity sum4 
(n1 in number,n2 in number) 
return number 
is 
temp number(8); 
start 
temp :=n1+n2; 
return temp; 
end; 
/ 

Presently, we should compose the basic system to call the capacity.

 

 import java.sql.*; 
public class FuncSum { 
public static void main(String[] args) throw Exception
{  
	Class.forName("oracle.jdbc.driver.OracleDriver"); 
	Association con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); 
	CallableStatement stmt=con.prepareCall("{?= call sum4(?,?)}"); 
	stmt.setInt(2,10); 
	stmt.setInt(3,43); 
	stmt.registerOutParameter(1,Types.INTEGER); 
	stmt.execute(); 
	System.out.println(stmt.getInt(1)); 
}
}