Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    Dale i Sunnfjord
    Posts
    8

    Unanswered: Insert Java-class from script

    Hi!

    I need some help on inserting Java-classes into Oracle 9idb.

    I need to be able to insert them also on db's where I do not have access to the file system. I inserted them locally and ran a dump. From the dmp-file I picked out the following lines:

    JAVA CLASS "com/enterprisedt/net/ftp/FTPConnectMode"

    EXECJAVA TATUS := DBMS_JAVA.START_IMPORT('com/enterprisedt/net/ftp/FTPConnectMode', 0, 29, 0, 3, 727, 1);
    EXECJAVA TATUS := DBMS_JAVA.IMPORT_TEXT_CHUNK('(("*" "KUNDE")("*" "PUBLIC"))', 29);
    EXECJAVA TATUS := DBMS_JAVA.IMPORT_RAW_CHUNK(HEXTORAW('00000000'), 4);
    EXECJAVA TATUS := DBMS_JAVA.IMPORT_RAW_CHUNK(HEXTORAW('636F6D2F656E7 46572707269736564742F6E65742F6674702F465450436F6E6 E6563744D6F6465'), 39);
    EXECJAVA TATUS := DBMS_JAVA.IMPORT_RAW_CHUNK(HEXTORAW('CAFEBABE00000 02E001E0A0008001508001609000400170700180A000400150 900040019090004001A07001B01000563767349640100124C6 A6176612F6C616E672F537472696E673B01000641435449564 50100294C636F6D2F656E746572707269736564742F6E65742 F6674702F465450436F6E6E6563744D6F64653B01000450415 3560100063C696E69743E010003282956010004436F6465010 00F4C696E654E756D6265725461626C650100083C636C696E6 9743E01000A536F7572636546696C65010013465450436F6E6 E6563744D6F64652E6A6176610C000E000F010043402823292 449643A20465450436F6E6E6563744D6F64652E6A6176612C7 620312E3220323030322F31312F31392032323A30313A32352 06272756365622045787020240C0009000A010027636F6D2F6 56E746572707269736564742F6E65742F6674702F465450436 F6E6E6563744D6F64650C000B000C0C000D000C0100106A617 6612F6C616E672F4F626A65637401000B6175726F72615F636 F64650100156175726F72615F66697273745F636F6E7374616 E7400210004000800000003000A0009000A00000009000B000 C00000009000D000C000000020002000E000F0002001000000 02100010001000000052AB70001B10000000100110000000A0 0020000004600040047001C0000002100010001000000052AD C0001B10000000100110000000A00020000004600040047000 80012000F000200100000003A000200000000001A1202B3000 3BB000459B70005B30006BB000459B70005B30007B10000000 100110000000E0003000000370005003C000F0041001C00000 03A000200000000001A1202DF180CBB000459DC0005DF2010B B000459DC0005DF2814B10000000100110000000E000300000 0370005003C000F004100020013000000020014001D0000000 2001C'), 684);
    EXECJAVA TATUS := DBMS_JAVA.END_IMPORT();
    ENDJAVA JAVA CLASS "com/enterprisedt/net/ftp/FTPConnectMode"


    Is there any way I can make these lines into a script runnable from SQL*Plus???


    I really hope anyone knows....


    Thanx
    -aj

  2. #2
    Join Date
    Aug 2003
    Posts
    40
    Here's an example of loading a Java class with three (3) static accessor
    methods and some PL/SQL implementation code.

    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "MyJavaClass" AS
    public class MyJavaClass {
    public static String getStringValue(String vString, Double vDouble, Integer vInteger) {
    return(vString + " with more text " + vDouble + " " + vInteger);
    }

    public static Integer getIntegerValue(String vString, Double vDouble) {
    return(new Integer(vDouble.intValue()));
    }

    public static Double getNumberValue(String vString, Integer vInteger) {
    return(new Double(vInteger.doubleValue()));
    }
    }
    /

    -- Here's the accompanying Oracle package code..

    CREATE OR REPLACE PACKAGE JavaTestPackage IS
    FUNCTION ReturnArrayToJava RETURN SimpleStringArrayType;
    PROCEDURE ObtainStringArrayFromJava(vReturnArray OUT SimpleStringArrayType);

    FUNCTION GetJavaStringValue(vString IN VARCHAR2,
    vDouble IN NUMBER,
    vInteger IN NUMBER) RETURN VARCHAR2;

    FUNCTION GetJavaIntegerValue(vString IN VARCHAR2,
    vDouble IN NUMBER) RETURN NUMBER;

    FUNCTION GetJavaNumberValue(vString IN VARCHAR2,
    vInteger IN NUMBER) RETURN NUMBER;
    END JavaTestPackage;
    /

    CREATE OR REPLACE PACKAGE BODY JavaTestPackage IS
    FUNCTION GetJavaStringValue(vString IN VARCHAR2,
    vDouble IN NUMBER,
    vInteger IN NUMBER) RETURN VARCHAR2 IS
    LANGUAGE JAVA NAME 'MyJavaClass.getStringValue(java.lang.String, java.lang.Double, java.lang.Integer) return java.lang.String';


    FUNCTION GetJavaIntegerValue(vString IN VARCHAR2,
    vDouble IN NUMBER) RETURN NUMBER IS
    LANGUAGE JAVA NAME MyJavaClass.getIntegerValue(java.lang.String, java.lang.Double) return java.lang.Integer';


    FUNCTION GetJavaNumberValue(vString IN VARCHAR2,
    vInteger IN NUMBER) RETURN NUMBER IS
    LANGUAGE JAVA NAME 'MyJavaClass.getNumberValue(java.lang.String, java.lang.Integer) return java.lang.Double';
    END JavaTestPackage;
    /

    -- Here's some PL/SQL implementation code you can run from SQL Plus...

    SET serveroutput ON SIZE 2000
    DECLARE
    vString VARCHAR2(100) := JavaTestPackage.GetJavaStringValue('Hello test', 2.25, 5);
    vInteger NUMBER := JavaTestPackage.GetJavaIntegerValue('Hello', 2.55);
    vNumber NUMBER := JavaTestPackage.GetJavaNumberValue('Hello', 6);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('String test: ' || vString);
    DBMS_OUTPUT.PUT_LINE('Integer test: ' || vInteger);
    DBMS_OUTPUT.PUT_LINE('Number test: ' || vNumber);
    END;
    /
    SET serveroutput OFF

    These examples provide datatype argument/return values of String,
    Integer, and Double from the java.lang library.

  3. #3
    Join Date
    Aug 2003
    Location
    Dale i Sunnfjord
    Posts
    8
    maybe that's the best way to solve it.

    thanks for your reply!

    -aj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •