Professional Documents
Culture Documents
Administration Tips
A word to the wise: that statement is case sensitive like you wouldnt believe! When I inadvertently tried it with its line 7 reading CreateStatement(); the second stage produced errors complaining that CreateStatement was not a method it was aware of. Quite right too: it knows about createStatement with the lower case c! If you cant manage to type all that in exactly, therefore, youll find a working, tested version on the Scripts page of this website. Second, in your Oracle_Home directory (wherever that might be) type the following command: loadjava u scott/tiger@SID r Test.java The SID there should obviously be replaced with the actual name of the Instance in which you wish to run this Java Stored Procedure. That must relate to an entry in your tnsnames.ora file.
Copyright Howard Rogers 2001 1/11/2001 Page 1 of 2
Administration Tips
If you havent got tnsnames.ora configured, then you can replace it with the usual host:port:sid connection string (where host is the name of your machine, and port Is the port on which the Listener is listening for connections to the Instance named by SID), but you also need to add in a new parameter, like this: loadjava thin u scott/tiger@host:port:sid r Test.java Note also the precise capitalisation of the Test.java name at the end of either of these variants of the command. What you are doing at this point is loading the text file we produced earlier into the database as a Java Stored Procedure. Third, you connect to the database as Scott, and create a procedure that calls the new Java Stored Procedure weve just created. You do that because JSPs cant be called directly, but only via PL/SQL. In other words: connect scott/tiger@SID create or replace procedure updatesal (empid in number, salary in number) as language java name Test.updateSal(int,int); / Again, capitalisation is important in that last line. Fourth and finally, its time to actually run the procedure. In SQL Plus, type: exec updatesal(7934,1000) Notice how this works you call the PL/SQL procedure, supplying the relevant parameters (in this case, employee number and new salary figure). The PL/SQL procedure then calls the Java Stored Procedure we earlier loaded into the database, passing it the supplied parameter values in the process, and it is the Java code which then does the actual updating and commiting of the requested update. If you follow all that with a normal select * from emp; you should see that employee 7934 now has a $1000 salary. And thats how you do it, more or less. Create Java procedures in a text editor, create Java Stored Procedures within the database by loading the code with the loadjava application, and then create a PL/SQL procedure which actually calls the Java procedure. Hopefully, that will give you enough to play around with, and see what else you can do!
1/11/2001
Page 2 of 2