Otherwise, the Java compiler will try to interpret the method as a class member or data structure.įigure 9.2: A simple Java class used to delete a file When you call a method that does not have any arguments (such as delete), you still must provide open and close parentheses. The assignment operator is a plain equals sign (=) rather than the complex symbol used in PL/SQL (:=). Java is case sensitive "if " is definitely not the same thing as "IF". Public static int delete (String fileName) ) to close the block. * Filename on companion disk: JDelete.java */ Here is the very simple class that I wrote to take advantage of the lete method: Return a value that PL/SQL interprets properly Instantiate an object from the File classĮxecute the delete method against that object I cannot pass a Boolean from Java back directly to a PL/SQL Boolean.Īs a direct consequence, I need to build my own class that will: From within PL/SQL, I cannot instantiate a Java object and then call the method against that object.Įven though Java and PL/SQL both have Boolean datatypes ( Java even offers a Boolean primitive and a Boolean class), they do not map to each other. Now, you might be asking yourself: why should Steven have to build his own Java class on top of the File class? Why can't I just call that function directly inside my PL/SQL wrapper? There are two reasons:Ī Java class method is, in almost every case (except for static methods), executed for a specific object instantiated from the class. It the file is deleted, the function returns TRUE otherwise, it returns FALSE. I will, in other words, call a Boolean function in Java to delete a file. Here is a portion of the API offered by the File class: It also contains methods (procedures and functions) to delete and rename files, make directories, and so on. There I found information about the class named java.io.File, namely, that it "provides a set of methods to obtain information about files and directories." Well, fortunately, it doesn't just let you obtain information. ![]() The entry for "File class" caught my eye and I hurried to page 161. , by Mark Grand and Jonathan Knudsen, and looked up "File" in the index (sure, I could use HTML documentation, too, but Iīooks). My O'Reilly & Associates editor, Deborah Russell, was kind enough to send me a whole bunch of their Java books, so I grabbed the big, fat Identify the Java functionality I need to access.īuild a class of my own to make the underlying Java feature callable through PL/SQL.Ĭompile the class and load it into the database.īuild a PL/SQL program to call the class method I created. Here are the steps I will perform in this demonstration: ) classes that offer clean, easy-to-use APIs to a wide array of functionality, including file I/O. Java, on the other hand, comes with prebuilt ( The external procedure implementation in Oracle 8.0 is a better solution, but it is far less than straightforward, especially if you don't know the C language. The pipe technique is handy, but it is a clumsy workaround. In Oracle 8.0, I could set up a library that pointed to a C DLL or shared library, and then from within PL/SQL, call a program in that library to delete the file. Prior to Oracle 8.1, I had the following options:Įven in Oracle 7.3, I could send a message to a database pipe, and then have a C listener program grab the message ("Delete file X") and do all the work. So here is my challenge: I need to be able to delete a file from within PL/SQL. ![]() ![]() In the process, I'll introduce the various pieces of technology you need to get the job done. Before diving into the details, let's just walk through all the different steps needed to access Java from within PL/SQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |