Welcome To The World Of Java

This site will teach you the basics of Java. It is not necessary to have any prior programming experience.

Write a java program which illustrates the concept of function?

Somdeb Burman | 9:51:00 AM | 0 comments


create or replace function StuFun(a in number, b in number, n1 out number) 
return number as n2 number;
begin
n1:=a*b;
n2:=a+b;
return (n2);
end;


import java.sql.*;

import java.io.*;
class FunConcept {
 public static void main(String[] args) {
   try {
    DriverManager.registerDriver(new 
    oracle.jdbc.driver.OracleDriver());
  System.out.println("DRIVERS LOADED...");
    Connection con = 
    DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:
     BudDinu " "scott " , "tiger ");
     System.out.println("CONNECTION OBTAINED..."); 
     DataInputStream dis = new DataInputStream(System.in);
     System.out.println("ENTER FIRST NUMBER : "); 
     String s1 = dis.readLine();
     System.out.println("ENTER SECOND NUMBER : "); 
     String s2 = dis.readLine(); 
     int n1 = Integer.parseInt(s1);
     int n2 = Integer.parseInt(s2); 
     CallableStatement cs = con.prepareCall("{?=call ArthFun (?,?,?)}"); 
     cs.setInt(2, n1); 
     cs.setInt(3, n2);
     cs.registerOutParameter(1, Types.INTEGER); 
     cs.registerOutParameter(4, Types.INTEGER); 
     cs.execute();
     int res = cs.getInt(1);
     int res1 = cs.getInt(4); 
     System.out.println("SUM OF THE NUMBERS : " + res); 
     System.out.println("MULTIPLICATION OF THE NUMBERS : " + res1);
    } catch (Exception e) {
     e.printStackTrace();
    }
   } // main
  } // FunConcept

Java Resources are available for Download from below

Category: , , ,

0 comments