This is PART II of JAVA with PL/SQL series. We will obtain operating system's information using JAVA in PL/SQL.
SQL> /* My database Version */
SQL> SELECT * FROM v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> /* Creating JAVA class */
SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED GetOperatingSystem AS
import java.util.*;
import java.lang.*;
import java.net.*;
public class GetOperatingSystem {
public static void GetOsInfo() {
try {
String osNameString=System.getProperty("os.name");
String osVersionString=System.getProperty("os.version");
String osArchString=System.getProperty("os.arch");
String osUserString=System.getProperty("user.name");
System.out.println("Operating System: " +osNameString);
System.out.println("Operating System Version: " +osVersionString);
System.out.println("Operating System Architecture: " +osArchString);
System.out.println("Operating System User Name: " +osUserString);
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception:"+ e.getMessage());
}
}
}
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 /
Java created.
SQL> /* Creating a wrapper procedure */
SQL> CREATE OR REPLACE PROCEDURE Get_OS
AS LANGUAGE JAVA
NAME 'GetOperatingSystem.GetOsInfo()'; 2 3
4 /
Procedure created.
SQL> set serverout on
SQL> BEGIN
DBMS_JAVA.SET_OUTPUT(1000000);
Get_OS;
END; 2 3 4
5 /
Operating System: Linux
Operating System Version: 2.6.31-23-generic
Operating System Architecture: i686
Operating System User Name:
PL/SQL procedure successfully completed.
SQL>
SQL> /* My database Version */
SQL> SELECT * FROM v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> /* Creating JAVA class */
SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED GetOperatingSystem AS
import java.util.*;
import java.lang.*;
import java.net.*;
public class GetOperatingSystem {
public static void GetOsInfo() {
try {
String osNameString=System.getProperty("os.name");
String osVersionString=System.getProperty("os.version");
String osArchString=System.getProperty("os.arch");
String osUserString=System.getProperty("user.name");
System.out.println("Operating System: " +osNameString);
System.out.println("Operating System Version: " +osVersionString);
System.out.println("Operating System Architecture: " +osArchString);
System.out.println("Operating System User Name: " +osUserString);
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception:"+ e.getMessage());
}
}
}
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 /
Java created.
SQL> /* Creating a wrapper procedure */
SQL> CREATE OR REPLACE PROCEDURE Get_OS
AS LANGUAGE JAVA
NAME 'GetOperatingSystem.GetOsInfo()'; 2 3
4 /
Procedure created.
SQL> set serverout on
SQL> BEGIN
DBMS_JAVA.SET_OUTPUT(1000000);
Get_OS;
END; 2 3 4
5 /
Operating System: Linux
Operating System Version: 2.6.31-23-generic
Operating System Architecture: i686
Operating System User Name:
PL/SQL procedure successfully completed.
SQL>
No comments :
Post a Comment