Call a stored procedure in java's CallableStatement interface to see the PROGRAM and MODULE columns in V $ ACTIVE_SESSION_HISTORY. (Oracle Database + java)

Oracle Database with callableStatement interface in java Call the stored procedure and call V $ ACTIVE_SESSION_HISTORY Let's see what is set in the PROGRAM column and MODULE column. 彡 (゚) (゚)

I wrote it while referring to the following site. I'm still unfamiliar with java, so there's a forgiveness and 彡 (-) (-)

Call stored procedures from JDBC (Oracle, SQL Server, MySQL) http://hito4-t.hatenablog.com/entry/2015/04/06/185902 Interface CallableStatement https://docs.oracle.com/javase/jp/8/docs/api/java/sql/CallableStatement.html try-with-resources statement * 8/11 postscript http://docs.oracle.com/javase/jp/7/technotes/guides/language/try-with-resources.html

The definition of the stored procedure is as follows (゜) (゜)

CREATE OR REPLACE PROCEDURE PRC_CALL_SP
IS
  d_date DATE;
BEGIN
  FOR i IN 1..1000000
  LOOP
    SELECT SYSDATE INTO d_date FROM DUAL;
  END LOOP;
END;
/

The sample of java source is as follows (゜) (゜)

import java.sql.*;

public class StoredCall {
    public static void main(String[] args) {
        //initialize
        System.out.println("Init...");
        //DB connection info
        final String path = "jdbc:oracle:thin:@localhost:1521:orcl";  //path
        final String id = "XXXXXXXX";  //ID
        final String pw = "YYYYYYYY";  //password
        
        //try-with-resources Statement
        try (
            //DB Connect
            Connection conn = DriverManager.getConnection(path, id, pw);
            //Stored Procedure Statement Set.
            CallableStatement cs = conn.prepareCall("CALL PRC_CALL_SP()");
        ) {
            //AutoCommit Setting
            conn.setAutoCommit(false);
            //Stored Procedure Execute
            System.out.println("Call stored procedure...");
            cs.execute();
            //Commit
            conn.commit();
        } catch(SQLException ex) {
            //SQLException
            ex.printStackTrace();  //Error
        }
        //End
        System.out.println("End...");
    }
}

What is Han's raw javac compilation, IDE? 彡 (゜) (゜)

javac -classpath .:${ORACLE_HOME}/jdbc/lib/ojdbc8.jar StoredCall.java

After all Han raw java execution, IDE is n (ry

java -classpath .:${ORACLE_HOME}/jdbc/lib/ojdbc8.jar StoredCall

As a result of executing the java module, this is just a message (゜) (゜)

Init...
Call stored procedure...
End...

Below is the reference result of V $ ACTIVE_SESSION_HISTORY, Both PROGRAM and MODULE are JDBC Thin Clients! 彡 (゜) (゜)

SET LINESIZE 170;
SET PAGESIZE 300;
COLUMN sid FORMAT 9999;
COLUMN ss FORMAT A10;
COLUMN event FORMAT A30;
COLUMN program FORMAT A20;
COLUMN module FORMAT A20;
SELECT session_id AS sid
  ,    sql_id
  ,    top_level_sql_id
  ,    session_state as ss
  ,    event
  ,    program
  ,    module
FROM v$active_session_history
WHERE sample_time >= systimestamp - (3 / 24 / 60)
AND user_id = 131
ORDER BY sample_time DESC;

  SID SQL_ID        TOP_LEVEL_SQL SS         EVENT                          PROGRAM              MODULE
----- ------------- ------------- ---------- ------------------------------ -------------------- --------------------
   17 1vq4vx6n0r4cn 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17               1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 1vq4vx6n0r4cn 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 c749bc43qqfz3 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 c749bc43qqfz3 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 1vq4vx6n0r4cn 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 c749bc43qqfz3 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17               1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 c749bc43qqfz3 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 c749bc43qqfz3 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
   17 c749bc43qqfz3 1vq4vx6n0r4cn ON CPU                                    JDBC Thin Client     JDBC Thin Client
:

SELECT sql_id, sql_text FROM V$SQL
WHERE sql_id IN ('1vq4vx6n0r4cn', 'c749bc43qqfz3');

SQL_ID        SQL_TEXT
------------- ---------------------------
c749bc43qqfz3 SELECT SYSDATE FROM DUAL
1vq4vx6n0r4cn CALL PRC_CALL_SP()

Recommended Posts

Call a stored procedure in java's CallableStatement interface to see the PROGRAM and MODULE columns in V $ ACTIVE_SESSION_HISTORY. (Oracle Database + java)
The story of forgetting to close a file in Java and failing
[Java] How to get the key and value stored in Map by iterative processing
3. Create a database to access from the web module
Write a class in Kotlin and call it in Java
Java classes and instances to understand in the figure
Using the database (SQL Server 2014) from a Java program 2018/01/04
Call a program written in Swift from Processing (Java)
A program (Java) that outputs the sum of odd and even numbers in an array
Java code sample to acquire and display DBLINK source and destination data in Oracle Database using DBLINK
Sample code to get the values of major SQL types in Java + Oracle Database 12c