Saturday, August 7, 2021

PLSQL Import Java loadjava

 public class Math{

  public static int Sum (int x, int y){

  return (x + y );

  }

  public static int difference (int x, int y ){

  return (x-y);

  }

}


loadjava -schema hr -user hr/hr@localhost:1521/XEPDB1 -verbose Math.java


loadjava -user USERNAME/PASSWORD@DBNAME -resolve -synonym activation.jar


select * from user_objects where created>sysdate-1;


CREATE OR REPLACE FUNCTION do_sum (x NUMBER, y NUMBER)

-- Return type should match the return type of java member function

RETURN NUMBER

AS

   LANGUAGE JAVA

   NAME 'Math.Sum(int,int) return int';

   

select do_sum(1,2) from dual


import java.sql.*;

import java.io.*;

import oracle.jdbc.*;


public class RowCounter

{

  public static int rowCount (String tabName) throws SQLException

  {

    Connection conn = DriverManager.getConnection("jdbc:default:connection:");

    String sql = "SELECT COUNT(*) FROM " + tabName;

    int rows = 0;

    try

    {

      Statement stmt = conn.createStatement();

      ResultSet rset = stmt.executeQuery(sql);

      while (rset.next())

      {

        rows = rset.getInt(1);

      }

      rset.close();

      stmt.close();

    }

    catch (SQLException e)

    {

      System.err.println(e.getMessage());

    }

    return rows;

  }

}


[appldev@ct11bzapp181 java]$ loadjava -force -user apps/fnd EchoInput.class

[appldev@ct11bzapp181 java]$ vi RowCounter.java

[appldev@ct11bzapp181 java]$ javac -target 1.5 RowCounter.java

[appldev@ct11bzapp181 java]$ loadjava -force -user apps/fnd RowCounter.class

[appldev@ct11bzapp181 java]$


CREATE FUNCTION row_count (tab_name VARCHAR2) RETURN NUMBER

AS LANGUAGE JAVA

NAME 'RowCounter.rowCount(java.lang.String) return int';

No comments:

Post a Comment