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