This discussion is archived
11 Replies Latest reply: Mar 1, 2013 10:45 AM by rp0428 RSS

calling java methods in plsql functions

RekhaVengadesan Newbie
Currently Being Moderated
Hai, i have a doubt in calling java methods through plsql functions ie. should we call only static methods. Pls any experts clear my query.

Thanks and Regards.

Edited by: wyse14 on Feb 25, 2013 9:19 PM
  • 1. Re: calling java methods in plsql functions
    Purvesh K Guru
    Currently Being Moderated
    wyse14 wrote:
    Hai, i have a doubt in calling java methods through plsql functions ie. should we call only static methods. Pls any experts clear my query.

    Thanks and Regards.

    Edited by: wyse14 on Feb 25, 2013 9:19 PM
    Not something I have read about, but it is no hard and fast rule.

    Are you using Java Stored Procedures? If not, maybe you should look at using it. It has several benefits.

    Read Developing Java Stored Procedures for benefits and example of developing it.
  • 2. Re: calling java methods in plsql functions
    rp0428 Guru
    Currently Being Moderated
    >
    Hai, i have a doubt in calling java methods through plsql functions ie. should we call only static methods. Pls any experts clear my query.
    >
    What do you mean 'calling java methods through plsql functions'?

    You can call Java stored procedures or Java functions and those Java procedures/functions/ call have static methods or instance methods.

    What is it you are trying to do? Do you have sample Java code you can post?
  • 3. Re: calling java methods in plsql functions
    RekhaVengadesan Newbie
    Currently Being Moderated
    Hai thanks for the reply,

    I have java code to send sms through GSM Modem.The method i have to call is of type synchronised not 'static' .I am not able to call through plsql functions.


    Note: i cannot change the type of method as static but i want to call this method.

    Any suggestions pls.

    Thanks and regards.
    Rekha.
  • 4. Re: calling java methods in plsql functions
    rp0428 Guru
    Currently Being Moderated
    >
    I have java code to send sms through GSM Modem.The method i have to call is of type synchronised not 'static' .I am not able to call through plsql functions.

    Note: i cannot change the type of method as static but i want to call this method.
    >
    All of that just sounds like gobbledy-gook to me; don't understand any of it.

    Why don't you post the code you are trying to use and any errors or stack traces that you are getting.

    Saying 'I am not able to call . . .' doesn't mean a thing to me. Why aren't you able to call? Do you get an error? How are you trying to call? What are you trying to call.

    You aren't giving us any information to work with.
  • 5. Re: calling java methods in plsql functions
    RekhaVengadesan Newbie
    Currently Being Moderated
    Hai, this is my java code , and i need to call method "SendMessage".I have created this java class in db but when i am calling this method(SendMessage) i am getting "no method found".Please suggest me how to call because it not of type static.




    public class Gsm implements SerialPortEventListener, CommPortOwnershipListener
    {
    /*
              * Instance Object Logger
              */
    private static Logger logger = Logger.getLogger(Gsm.class);

    /*
              * Constance status
              */
    public static final int SC_OK = 0;
    public static final int SC_ERROR = 1;
    public static final int SC_PDU_PARSE_ERROR = 2;

    /*
              * Flux I/O
              */
    private OutputStream outStream;
    private InputStream inStream;

    /*
              * Read incoming SMS from SIM
              */
    private IncomingSms rx_sms = null;

    /*
              * Config Serial Port
              */
    private SerialParameters parameters;

    /*
              * Communication scan port
              */
    private CommPortIdentifier portId;

    /*
              * Communication in serial port
              */
    private SerialPort sPort;


    /*
              * Status comm port
              */
    public int portStatus = OK;
    private static Boolean portStatusLock = new Boolean(true);
    private boolean POLLING_FLAG;
    private String portStatusMsg = "";

    /*
              * Type of response
              */
    private static final int OK = 1;
    private static final int WAIT = 2;
    private static final int ERROR = 3;
    private static final int WMSG = 4;
    private static final int RMSG = 5;
    private static final int ECHO = 6;
    private static final int TIMEOUT = 7;

    /*
              * Buffer serial incoming event
              */
    private byte[] readBuffer = new byte[20000];
    private int bufferOffset = 0; // serialEvent

    /*
              * LF CR
              */
    private static final String lfcr = "\r\n";

    /*
              * Default index memory is 1
              */
    private int indexCurrentMemory = 1;

    /*
              * Default memory is "SM"
              */
    private String currentMemory = "\"SM\"";

    /**
    * Constructor!
    *
    * @param parameters
    */
    public Gsm(SerialParameters parameters) {
    this.parameters = parameters;
    }


    /**
    * Initialize driver to be able to connect to serial port
    * incase application is running from Windows
    * as u might expect no driver initialization is required on linux
    * ensure you initialize only once on Windows so as to avoid multiple port enumeration
    *
    * @return String      "suncessful" or "failure"
    */
    public String initializeWinDrivers() {
    String drivername = "com.sun.comm.Win32Driver";
    try {
    CommDriver driver =
    (CommDriver)Class.forName(drivername).newInstance();
    driver.initialize();
    return "successful";
    } catch (Exception e) {
    // Discard it
    return "failure";
    }
    }

    /**
    * Return type of serial port (depend type of driver!) Driver=com.sun.comm.Win32Driver (window)
    * Driver=gnu.io.RXTXCommDriver (all platform)
    *
    * @param portType
    * @return String with driver type
    */
    static String getPortTypeName(int portType) {
    // we use on window...
    switch (portType) {
    case CommPortIdentifier.PORT_PARALLEL:
    return "Parallel";
    case CommPortIdentifier.PORT_SERIAL:
    return "Serial";
    default:
    return "unknown type";
    }
    }

    /**
    * Open serial connection with COM port
    *
    * @param _port
    * @throws IOException
    */
    public void openConnection(String _port) throws IOException {
    openConnection(_port, null);
    }

    /**
    * Open serial connection with COM port
    *
    * @param _port
    * @param _pinNumber
    * @throws IOException
    */
    public void openConnection(String _port,
    String _pinNumber) throws IOException {
    String port = _port;
    if (_port == null)
    port = parameters.getPortName();

    // Obtain a CommPortIdentifier object for the port you want to open.
    try {
    portId = CommPortIdentifier.getPortIdentifier(port);
    System.out.println("portId******" + portId);
    } catch (Exception e) {
    e.printStackTrace();

    }

    // Open the port represented by the CommPortIdentifier object. Give
    // the open call a relatively long timeout of 30 seconds to allow
    // a different application to reliquish the port if the user
    // wants to.
    try {
    sPort = (SerialPort)portId.open("MobilePartner", 5000);
    System.out.println("Inside sPort" + sPort);
    } catch (Exception e) {
    e.printStackTrace();
    }

    // Set the parameters of the connection. If they won't set, close the
    // port before throwing an exception.
    try {
    setConnectionParameters();
    } catch (Exception e) {
    sPort.close();

    }

    // Open the input and output streams for the connection. If they won't
    // open, close the port before throwing an exception.
    try {
    outStream = sPort.getOutputStream();
    inStream = sPort.getInputStream();
    } catch (Exception e) {
    sPort.close();
    throw new IOException("Error opening i/o streams");
    }
    // Add this object as an event listener for the serial port.
    try {
    sPort.addEventListener(this);
    } catch (Exception e) {
    sPort.close();
    throw new IOException("too many listeners added");
    }

    // Set notifyOnDataAvailable to true to allow event driven input.
    sPort.notifyOnDataAvailable(true);

    // Add ownership listener to allow ownership event handling.
    portId.addPortOwnershipListener(this);

    // init modem connection with pin number
    initializeModem(_pinNumber);
    }

    /**
    * Initialize modem with PIN number
    *
    * @param pinNumber
    */
    private void initializeModem(String pinNumber) {
    atCmd("ATE0", 0, 1000); // turn off command echo
    atCmd("AT+CMEE=2", 0, 500); // verbose all messages
    atCmd("AT+CMGF=0", 0, 500); // set Pdu mode (default binary)
    //atCmd("AT+CNMI=0,0,0,0", 0, 500);// disable indications -direct to TE?

    if (pinNumber != null) {
    //enter pin number
    atCmd("AT+CPIN=\"" + pinNumber + "\"", 0, 1000);
    if (portStatus == ERROR) {
    logger.error("The pin number " + pinNumber +
    " is INCORRECT. Please try again.");
    // close session!
    this.close();
    }
    }
    }

    /**
    * List open serial port
    *
    * @return Array String
    */
    public String[] listPorts() {
    Enumeration ports = CommPortIdentifier.getPortIdentifiers();
    ArrayList portList = new ArrayList();
    String portArray[] = null;
    while (ports.hasMoreElements()) {
    CommPortIdentifier port = (CommPortIdentifier)ports.nextElement();
    if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    portList.add(port.getName());
    }
    portArray = (String[])portList.toArray(new String[0]);
    }
    return portArray;
    }

    /**
    * Handles ownership events. If a PORT_OWNERSHIP_REQUESTED event is received a dialog box is created asking the user
    * if they are willing to give up the port. No action is taken on other types of ownership events.
    */
    public void ownershipChange(int type) {
    if (type == CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED) {
    logger.debug("PORT_OWNERSHIP_REQUESTED received : Your port has been requested by an other application...");

    this.close();
    } else if (type == CommPortOwnershipListener.PORT_OWNED) {
    logger.debug("PORT_OWNED received!");
    } else if (type == CommPortOwnershipListener.PORT_UNOWNED) {
    logger.debug("PORT_UNOWNED received!");
    }
    }

    /**
    * Sets the connection parameters to the setting in the parameters object. If set fails return the parameters object
    * to origional settings and throw exception.
    */
    private void setConnectionParameters() throws IOException {
    // Save state of parameters before trying a set.
    int oldBaudRate = sPort.getBaudRate();
    int oldDatabits = sPort.getDataBits();
    int oldStopbits = sPort.getStopBits();
    int oldParity = sPort.getParity();
    int oldFlowControl = sPort.getFlowControlMode();

    // Set connection parameters, if set fails return parameters object
    // to original state.
    try {
    sPort.setSerialPortParams(parameters.getBaudRate(),
    parameters.getDatabits(),
    parameters.getStopbits(),
    parameters.getParity());
    } catch (Exception e) {
    parameters.setBaudRate(oldBaudRate);
    parameters.setDatabits(oldDatabits);
    parameters.setStopbits(oldStopbits);
    parameters.setParity(oldParity);
    parameters.setFlowControlIn(oldFlowControl);
    parameters.setFlowControlOut(oldFlowControl);
    throw new IOException("Unsupported parameter");
    }
    // Set flow control.
    try {
    sPort.setFlowControlMode(parameters.getFlowControlIn() |
    parameters.getFlowControlOut());
    sPort.enableReceiveThreshold(1);
    sPort.enableReceiveTimeout(2000); // timeout 2s ?!
    } catch (Exception e) {
    throw new IOException("Unsupported flow control");
    }
    }

    // To be used to send AT command via the IR/serial link to the mobile
    // device (for standard AT commands use mode=0)

    private synchronized int atCmd(String cmd, int mode, int timeout) {
    System.err.println(cmd);
    logger.debug(cmd);
    synchronized (portStatusLock) {
    portStatus = WAIT;
    try {
    // normal end of at command
    if (mode == 0)
    outStream.write((cmd + lfcr).getBytes());

    // end of pdu <CTRL+Z>
    if (mode == 1)
    outStream.write((cmd + "\u001A").getBytes());

    // no lfcr: used for polling (just echoed back)
    if (mode == 2)
    outStream.write((cmd).getBytes());
    } catch (Exception e) {
    ;
    }

    // wait for response from device
    try {
    // Respond time can vary for different types of AT commands and mobiles!
    portStatusLock.wait(timeout);
    } catch (Exception e) {
    //...
    e.printStackTrace();
    }
    }
    return OK;
    }

    /**
    * Terminates IR/Serial connection to Mobile device
    */
    public void close() {
    // Turn on again command echo
    atCmd("ATE1", 0, 1000);
    if (sPort != null) {
    try {
    // close the i/o streams.
    outStream.close();
    inStream.close();
    } catch (Exception e) {
    System.err.println(e);
    }

    // Close the port.
    sPort.close();

    // Remove the ownership listener.
    // portId.removePortOwnershipListener(this);
    }
    }

    /**
    * Listener Function: Data received from serial link and interpreted
    */
    public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    int n;
    try {
    if (POLLING_FLAG == false) {
    while ((n = inStream.available()) > 0) {
    n = inStream.read(readBuffer, bufferOffset, n);
    bufferOffset += n;
    String sbuf =
    new String(readBuffer, 0, bufferOffset); // bufferOffset-2

    // lfcr detected, line ready
    if (((readBuffer[bufferOffset - 1] == 10) && (readBuffer[bufferOffset - 2] == 13))) {
    // analyzing mobile response
    lineReceived(sbuf);
    if ("ERROR".equals("error msg" + portStatusMsg)) {
    System.out.println(portStatusMsg);
    logger.debug(portStatusMsg);
    }
    bufferOffset = 0;
    }
    }

    // delay 1/10 sec
    try {
    Thread.sleep(100);
    } catch (Exception e) {
    e.printStackTrace();
    }
    } else
    portStatus = ECHO;
    } catch (Exception e) {
    ;
    }
    break; // end: case SerialPortEvent.DATA_AVAILABLE:
    }
    }

    /**
    * Used for analyzing mobile response
    */
    private void lineReceived(String buffer) {
    String response;
    StringTokenizer st = new StringTokenizer(buffer, "\r\n");
    rx_sms = null;
    synchronized (portStatusLock) {
    while (st.hasMoreTokens()) {
    response = st.nextToken();
    System.out.println("response ==" + response);
    logger.debug(response);
    System.out.println(response);
    if (response.startsWith("OK")) {
    portStatus = OK;
    portStatusLock.notify();
    } else if (response.startsWith(">")) {
    portStatus = WMSG;
    portStatusMsg = response;
    } else if (response.startsWith("ERROR")) {
    portStatus = ERROR;
    portStatusMsg = response;
    } else if (response.startsWith("+CME ERROR") ||
    response.startsWith("+CMS ERROR")) {
    portStatus = ERROR;
    portStatusMsg = response;
    } else if (response.startsWith("07") ||
    response.startsWith("00")) {
    portStatus = RMSG;
    try {
    rx_sms = new IncomingSms(response);
    logger.debug("SMS received: " + rx_sms.toString());
    portStatusLock.notify();
    } catch (Exception e) {
    logger.error("Error receiving SMS message: unable to parse PDU:\r\n" +
    response);
    portStatus = ERROR;
    }
    }
    // read sms response
    else if (response.startsWith("+CPMS")) // list sms SM, ME or MT
    {
    portStatus = RMSG;
    portStatusMsg = response;
    } else if (response.startsWith("+CMGR")) // read sms OK
    {
    portStatus = RMSG;
    portStatusMsg = response;
    }
    // read phonebook response
    else if (response.startsWith("+CPBR")) // read index phonebook OK
    {
    portStatus = RMSG;
    portStatusMsg = response;
    } else if (response.startsWith("+CPBS")) // read current phonebook memory OK
    {
    portStatus = RMSG;
    portStatusMsg = response;
    } else if (response.startsWith("+CPBF")) // read find phonebook OK
    {
    portStatus = RMSG;
    portStatusMsg = response;
    }
    // other tips
    else if (response.startsWith("ATE0")) // snoop echo
    {
    portStatus = ECHO;
    portStatusMsg = response;
    } else {
    //...
    }
    }
    }
    return;
    }

    /**
    * Send an SMS to number (using SMS central having number "smsc_number")
    */

    public synchronized void SendMessage(String number, String smsc_number, String msg) {
    // to specify specific SMS settings (character coding, sms type, ...)

    SerialParameters params = new SerialParameters();
    params.setPortName("COM9"); // default COM1
    params.setBaudRate(115200); // default 115200
    params.setFlowControlIn(SerialPort.FLOWCONTROL_NONE); // default none flowcontrol
    params.setFlowControlOut(SerialPort.FLOWCONTROL_NONE); // default none flowcontrol
    params.setDatabits(SerialPort.DATABITS_8); // default data bits 8
    params.setStopbits(SerialPort.STOPBITS_1); // default stop bits 1
    params.setParity(SerialPort.PARITY_NONE); // default none parity bits 1
    System.out.println("Driver loading... " + initializeWinDrivers());
    // object sms client
    int tpPid = 0x00;
    int tpDcs = 0x00;
    if (number.startsWith("+"))
    number = number.substring(1);
    if (smsc_number.startsWith("+"))
    smsc_number = smsc_number.substring(1);
    try {
    //lets use a single SerialComm object to initialize everything
    String[] portArray = listPorts();
    System.out.println("Number of ports detected: " +
    portArray.length);
    for (int i = 0; i < portArray.length; i++) {
    System.out.println("OPEN serial Port : " + portArray);
    }
    System.out.println();

    // open connection serial port
    openConnection("COM9"); //, "1111"); // COM1, optional pin code
    System.out.println("sms.getPortStatus() " + getPortStatus());
    if (getPortStatus() == ERROR)
    System.out.println("----> Error : SMS not SEND !");
    else if (getPortStatus() == OK)
    System.out.println("----> Ok : SMS SEND - check folder on SIM!");

    // init write memory sms "\"ME\",\"SM\",\"MT\"
    boolean initMemSms = initializeSmsMemory("\"SM\"");
    System.out.println("Init Sms Memory : " + initMemSms);

    // get size sms storage
    int len_sms = getSizeListSMS();
    System.out.println("Size stored SMS : " + len_sms);

    // start index is 1 !?
    int index_sms = getIndexMemory();
    for (int i = index_sms; i <= len_sms; i++) {
    // read sms
    ReadSMS(i);

    // test if last message is a error
    if (getPortStatusMsg().startsWith("+CMS ERROR"))
    break;
    System.out.println("sms.getRxMS()****" + getRxMS());
    // get incoming sms
    IncomingSms in_sms = getRxMS();
    System.out.println("in_sms" + in_sms);
    if (in_sms != null) {
    System.out.println("\nSMS received : " +
    in_sms.toString());
    //sms.DeleteSMS(i);
    } else
    System.out.println("\nProblem SMS received !!!");
    }
    OutgoingSms pdumsg =
    new OutgoingSms(number, smsc_number, msg, tpPid, tpDcs);
    String cmd = "AT+CMGS=" + pdumsg.length();
    String pdu = pdumsg.toString();

    // Delay needed -> Waiting for ">" Prompt, otherwise Error MSG!
    atCmd(cmd, 0, 500);

    // For some mobiles > 1000 ms!
    atCmd(pdu, 1, 3500);

    } catch (Exception e) {
    System.err.println("Communication problem :" + e);
    e.printStackTrace();
    } finally {
    // close connection to serial port / modem
    try {
    close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    /**
    * Send an SMS from index memory
    */
    public synchronized void SendMessageStore(int index_mem, String number) {
    if (number.startsWith("+"))
    number = number.substring(1);
    try {
    // AT+CMSS= index [,da [,toda]]
    String cmd = "AT+CMSS=" + index_mem + "," + number;
    atCmd(cmd, 0, 3000);
    } catch (Exception e) {
    logger.error("Irregular SMS format");
    }
    }

    /**
    * Write SMS to phone/SIM memory (transmit format)
    */
    public synchronized void WriteTextMessage(String number,
    String smsc_number, String msg) {
    // to specify specific SMS settings (character coding, sms type, ...)
    int tpPid = 0x00;
    int tpDcs = 0x00;
    if (number.startsWith("+"))
    number = number.substring(1);
    if (smsc_number.startsWith("+"))
    smsc_number = smsc_number.substring(1);
    try {
    OutgoingSms pdumsg =
    new OutgoingSms(number, smsc_number, msg, tpPid,
    tpDcs);
    String cmd = "AT+CMGW=" + pdumsg.length();
    String pdu = pdumsg.toString();
    atCmd(cmd, 0, 500);
    atCmd(pdu, 1, 1500);
    } catch (Exception e) {
    logger.error("Irregular SMS format");
    }
    }

    /**
    * Write SMS to phone/SIM memory (received format, write problem with some phone/SIM)
    */
    public synchronized void WriteTextUnReadMessage(String number,
    String smsc_number,
    String msg) {
    // to specify specific SMS settings (character coding, sms type, ...)
    int tpPid = 0x00;
    int tpDcs = 0x00;
    if (number.startsWith("+"))
    number = number.substring(1);
    if (smsc_number.startsWith("+"))
    smsc_number = smsc_number.substring(1);
    try {
    OutgoingSms pdumsg =
    new OutgoingSms(number, smsc_number, msg, tpPid, tpDcs);
    Calendar time = new GregorianCalendar();
    //time.set(Calendar.MINUTE, -5);
    pdumsg.transform_to_received_SMS(time);
    String pdu_r = pdumsg.toString();

    // Important: PDU of SMS to be stored in RECEIVED UNREAD (,0) folder
    // must follow received SMS PDU format!
    String cmd_r = "AT+CMGW=" + pdumsg.length() + ",0";
    atCmd(cmd_r, 0, 500);
    atCmd(pdu_r, 1, 1500);
    } catch (Exception e) {
    logger.error("Irregular SMS format");
    }
    }

    /**
    * Read SMS from Mobile/SIM storage having index i
    */
    public synchronized void ReadSMS(int i) {
    atCmd("AT+CMGR=" + i, 0, 1000); // Receive SMS
    }

    /**
    * Delete SMS from Mobile/SIM storage having index i
    */
    public synchronized void DeleteSMS(int i) {
    atCmd("AT+CMGD=" + i, 0, 1000); // Delete SMS
    }

    /**
    * get SMS from Mobile/SIM storage
    */
    public synchronized IncomingSms getRxMS() {
    return rx_sms;
    }


    public synchronized String getPortStatusMsg() {
    return portStatusMsg;
    }

    /**
    * get port status...
    */
    public synchronized int getPortStatus() {
    return portStatus;
    }

    /**
    * Get current size list of SMS strored in particulary memory example = \"ME\",\"SM\",\"MT\"
    * "ME": ME phonebook
    * "SM": SIM phonebook
    * "MT": combined ME and SIM phonebook
    *
    * @return int Size list of sms in specific memory
    */
    public synchronized int getSizeListSMS() {
    atCmd("AT+CPMS=" + currentMemory, 0, 500);

    // receive error message ?
    if (portStatus == ERROR)
    return 1; // index list start 1 not 0!

    // parse response
    System.out.println("portStatusMsg+ " + portStatusMsg);
    try {
    String str =
    portStatusMsg.substring(portStatusMsg.indexOf(':') + 1,
    portStatusMsg.length());
    System.out.println("str " + str);
    String[] str2 = getArrayString(str);
    if (str2.length >= 2)
    str = str2[1]; // size used
    str = str.trim();

    // index current memory
    indexCurrentMemory = 1; // 1 for Sms

    return Integer.parseInt(str);
    } catch (Exception e) {
    return 1;
    }
    }


    /**
    * Method getSmsMemory
    *
    * @return String     Name of current sms memory
    */
    public synchronized String getSmsMemory() {
    String memory = "";

    // ask memory
    atCmd("AT+CPMS?", 0, 500);

    // receive error message ?
    if (portStatus == ERROR)
    return memory;

    try {
    memory =
    portStatusMsg.substring(portStatusMsg.indexOf('"'), portStatusMsg.indexOf('"') +
    4);
    memory = memory.trim();

    currentMemory = memory;
    } catch (Exception e) {
    return "";
    }
    return memory;
    }


    /**
    * Init current phone book memory
    *
    * @param typeStore
    * @return boolean          true if memory is initialized
    */
    public synchronized boolean initializePhoneBookMemory(String typeStore) {
    boolean initOk = true;

    // inint memory
    atCmd("AT+CPBS=" + typeStore, 0, 500);

    // receive error message ?
    if (portStatus == ERROR)
    return false;

    // set current type memory
    currentMemory = typeStore;

    return initOk;
    }

    /**
    * Init current sms memory
    *
    * @param typeStore
    * @return boolean          true if memory is initialized
    */
    public synchronized boolean initializeSmsMemory(String typeStore) {
    boolean initOk = true;

    // inint memory
    atCmd("AT+CPMS=" + typeStore, 0, 500);

    // receive error message ?
    if (portStatus == ERROR)
    return false;

    // set current type memory
    currentMemory = typeStore;

    return initOk;
    }

    /**
    * Get index of the current memory
    *
    * @return int
    */
    public int getIndexMemory() {
    return this.indexCurrentMemory;
    }

    /**
    * Method getArrayString
    *
    * @param response
    * @return String[]
    */
    private static String[] getArrayString(String _str) {
    // test _str
    if (_str == null)
    return new String[0];
    StringTokenizer b_stk = new StringTokenizer(_str, ",");
    String[] str = new String[b_stk.countTokens()];
    int count = 0;
    while (b_stk.hasMoreTokens())
    str[count++] = b_stk.nextToken();
    return str;
    }
    }

    Edited by: Rekha Vengadesan on Feb 26, 2013 11:37 PM
  • 6. Re: calling java methods in plsql functions
    Purvesh K Guru
    Currently Being Moderated
    I think you did not understand what rp0428 meant.

    We need to know and understand how you are calling Java methods from PL/SQL. Since, this is PL/SQL forum, posting Java code would not be of much help. So, it will be a lot better if you can show how you are trying to call the Java class from PL/SQL.

    In my understanding, you should be using JSP (Java Stored Procedures). I have posted a link in my previous post that demonstrates an example.

    Here is another with detailed steps to be followed. JSP.
  • 7. Re: calling java methods in plsql functions
    rp0428 Guru
    Currently Being Moderated
    >
    Hai, this is my java code , and i need to call method "SendMessage".I have created this java class in db but when i am calling this method(SendMessage) i am getting "no method found".Please suggest me how to call because it not of type static.
    >
    Non-static methods have to be called on an instance of the class. A direct call from Oracle has no instance to deal with. So the only way to call a non-static method is to call a static method that creates an instance of a class and then call the non-static method of that new instance.

    You need to create a Java stored procedure that uses your Java class. Part of the process involves loading your class into the DB.

    See the section 'Java Stored Procedures Steps' in the Java Dev Guide
    http://docs.oracle.com/cd/B28359_01/java.111/b31225/chfive.htm#BABGEJDI
    >
    The following steps are involved in creating, loading, and calling Java stored procedures:

    •Step 1: Create or Reuse the Java Classes
    •Step 2: Load and Resolve the Java Classes
    •Step 3: Publish the Java Classes
    •Step 4: Call the Stored Procedures
    •Step 5: Debug the Stored Procedures, if Necessary
    >
    That same doc shows how to call Java methods: '3 Calling Java Methods in Oracle Database'
    http://docs.oracle.com/cd/B28359_01/java.111/b31225/chthree.htm
  • 8. Re: calling java methods in plsql functions
    RekhaVengadesan Newbie
    Currently Being Moderated
    Thanks for the reply,


    Finally I have loaded the java class and called it through PLSQL function. And now I am getting this error

    Security Exception win32com: java.security.AccessControlException: the
    Permission (java.lang.RuntimePermission loadLibrary.win32com) has not been
    granted to HR. The PL/SQL to grant this is dbms_java.grant_permission( 'HR',
    'SYS:java.lang.RuntimePermission
    ', 'loadLibrary.win32com', '' )
    Driver loading... successful
    Communication problem :java.lang.NullPointerException: name can't be null
    java.lang.NullPointerException: name can't be null
    at java.io.FilePermission.init(FilePermission.java:171)
    at java.io.FilePermission.<init>(FilePermission.java:264)
    at java.lang.SecurityManager.checkDelete(SecurityManager.java:986)
    at javax.comm.CommPortIdentifier.getPortIdentifiers(CommPortIdentifier.java:70)
    at Gsm.listPorts(Gsm:277)
    at Gsm.SendMessage(Gsm:557)
    at Gsm.param(Gsm:877)
    java.lang.NullPointerException: name can't be null
    at java.io.FilePermission.init(FilePermission.java:171)
    at java.io.FilePermission.<init>(FilePermission.java:264)
    at java.lang.SecurityManager.checkDelete(SecurityManager.java:986)
    at javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:89)
    at Gsm.openConnection(Gsm:192)
    at Gsm.openConnection(Gsm:169)
    at Gsm.SendMessage(Gsm:615)
    at Gsm.param(Gsm:877)
    java.lang.NullPointerException
    at Gsm.openConnection(Gsm:204)
    at Gsm.openConnection(Gsm:169)
    at Gsm.SendMessage(Gsm:615)
    at Gsm.param(Gsm:877)



    can u help me to get through it.

    Thanks and Regards

    Rekha
  • 9. Re: calling java methods in plsql functions
    John Stegeman Oracle ACE
    Currently Being Moderated
    Rekha,

    Did you (gasp) read the error message? It not only tells you exactly what the problem is, but also tells you the PL/SQL code you can run to grant the missing permission.

    John
  • 10. Re: calling java methods in plsql functions
    RekhaVengadesan Newbie
    Currently Being Moderated
    Thanks John for the reply,

    So I have given all the permission and now no such issues but when i call the java class the process is very slow , am i stuck somewhere.


    Thanks and Regards

    Rekha
  • 11. Re: calling java methods in plsql functions
    rp0428 Guru
    Currently Being Moderated
    Well there isn't any way that we can help since we have no idea what it is you are even trying to do.

    You should execute your Java code manually outside of the DB until it works properly.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points