3. One method I recommend is to directly load and create remotely using the loadjava command.
Create a class first.
Copy the codeThe code is as follows:
import .*;
import .*;
public class OracleJavaProc ...{
//Add a salgrade to the database.
public static void addSalGrade(int grade, int losal, int hisal) ...{
("Creating new salgrade for EMPLOYEE...");
try ...{
Connection conn =
("jdbc:default:connection:");
String sql =
"INSERT INTO salgrade " +
"(GRADE,LOSAL,HISAL) " +
"VALUES(?,?,?)";
PreparedStatement pstmt = (sql);
(1,grade);
(2,losal);
(3,hisal);
();
();
}
catch(SQLException e) ...{
("ERROR! Adding Salgrade: "
+ ());
}
}
}
Use the loadjava command to load it to the server and compile:
Copy the codeThe code is as follows:
D:eclipse3.1workspacedbtest>loadjava -u scott/tiger@ -v -resolve Or
arguments: '-u' 'scott/tiger@ '-v' '-resolve' ''
creating : source OracleJavaProc
loading : source OracleJavaProc
resolving: source OracleJavaProc
Check the status:
Connect to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
Copy the codeThe code is as follows:
SQL> SELECT object_name, object_type, status FROM user_objects WHERE object_type LIKE 'JAVA%';
OBJECT_NAME
--------------------------------------------------------------------------------
OBJECT_TYPE STATUS
------------------------------------ --------------
OracleJavaProc
JAVA CLASS VALID
OracleJavaProc
JAVA SOURCE VALID
Test the stored procedure:
Copy the codeThe code is as follows:
SQL> create or replace procedure add_salgrade(id number, losal number, hisal num
ber) as language java name '(int, int, int)';
2 /
The process has been created.
SQL> set serveroutput on size 2000
SQL> call dbms_java.set_output(2000);
The call is completed.
SQL> execute add_salgrade(6, 10000, 15000);
Creating new salgrade for EMPLOYEE...
The PL/SQL process has been successfully completed.
SQL> select * from salgrade where grade=6;
GRADE LOSAL HISAL
---------- ---------- ----------
6 10000 15000
Previous page123Next pageRead the full text