Return array of varchar from oracle to java

Hi,
I am trying to return an array of varchar from database to java. However, when I print the values in java, it prints hexadecimal values like this.
0x656E7472792031
0x656E7472792032
0x656E7472792033
0x656E7472792034
I am using oracle 9.2.0.5.0 and jdk 1.4
This happens only when the NLS character set of the database is WE8MSWIN1252 (default character set).
It works fine on databases with UTF8 and US7ASCII character sets.
Any leads to the reason behind this behaviour is greatly aprpeciated.
Here's the code snippet...
<code>
//USER DEFINED TYPE
create or replace type SimpleArray
 as table of varchar2(30)
</code>
<code>
// FUNCTION RETURNING USER DEFINED TYPE
create or replace function getSimpleArray return SimpleArray
 as
 l_data simpleArray := simpleArray();
 begin
  for i in 1 .. 10 loop
      l_data.extend;
      l_data(l_data.count) := 'entry ' || i;
    end loop;
    return l_data;
  end;
</code>
<code>
// JAVA METHOD
public static void main(String[] args)
     try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
          String url = "jdbc:oracle:thin:@localhost:1521:db1252";
          Connection conn = DriverManager.getConnection(url, "ring", "ring");
          CallableStatement stmt = conn.prepareCall("{? = call "
                         + "getSimpleArray" + "}");
          Array rs = null;
          ResultSet rsltSet = null;
          stmt.registerOutParameter(1, Types.ARRAY, "SIMPLEARRAY");
          stmt.execute();
          rs = stmt.getArray(1);
          String[] values = (String[]) rs.getArray();
          System.out.println(rs.getBaseTypeName());
          System.out.println(values.length);
          for (int i = 0; i < values.length; i++) {
               System.out.println(values);
          rsltSet = rs.getResultSet();
     } catch (Exception e) {
          System.err.println("Got an exception! ");
          System.err.println(e.getMessage());
</code>
Thanks,
Vivek

Actually, check nls_charset12.zip. It looks like 9.2.0.5 driver contains only the *.zip version. Make sure that the file exists in the directory pointed by the CLASSPATH. Use full path, do not use %ORACLE_HOME%.
I have reproduced your problem without nls_charset12.zip and I could not reproduce it with the file in the class path. Double-check how classpath is set in your environment. Maybe it is overriden by some configuration or batch file.
-- Sergiusz

Similar Messages

  • Can i return an Array of Objects from c++ to java ??

    hello all,
    Can i return an Array of Objects from c++ to java ??
    If so how is it possible ??
    regards,
    gautam

    I suggest you look into the JNI, Java Native Interface. The answer is yes.

  • How to call a BPEL process from Oracle Apps Java Concurrent program

    Hello,
    I need to trigger a BPEL process from Oracle Apps. Can anybody tell me how to do that? I have two triggering option--
    1. On button click from a Form 6i screen
    2. Using Java Concurrent program.
    Thanks in advance.
    Debkanta

    I am not sure how concurrent program works, but may be one of the way might work out, let me know if Java Concurrent Program works a bit different way
    - [if async] Through concurrent program, you can insert message token to db or aq, and BPEL can be instantiated from there
    or
    - If it supports pure java call, then you can look at multiple documents (e.g. http://www.oracle.com/technology/products/ias/bpel/pdf/orabpel-Tutorial7-InvokingBPELProcesses.pdf) to invoke your process
    - You can also use oracle db utility to invoke soap operation and get the result back
    HTH,
    Chintan

  • Using mysql-connector-java-5.0.5 from oracle's java procedure.

    I need to write the java procedure in Oracle, which will get connection to mySQL server and put some data into it. I am using official mysql-connector-java-5.0.5 driver for this job. Java class for this job work well outside the Oracle. The problem is:
    When I try to import jar file of mysql connectior it fail son resolving inside the Oracle db. How can I get access to mysql from Oracle?

    Thanks for this quick reply!!
    --When adding a connection and clicking 'Test' in the end of the wizard or when right-click on the connection and click 'connect'.
    Also, I've just noticed this: when I start IDE using jdev.exe I'm getting:
    java.lang.NullPointerException at oracle.jdevimpl.cm.dt.DatabaseAddin._registerIDEObjects(DatabaseAddin.java:353)
    at oracle.jdevimpl.cm.dt.DatabaseAddin.initialize(DatabaseAddin.java:155
    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddin(AddinManage
    rImpl.java:425)
    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddins(AddinManag
    erImpl.java:240)
    at oracle.ideimpl.extension.AddinManagerImpl.initProductAndUserAddins(Ad
    dinManagerImpl.java:154)
    at oracle.ide.IdeCore.initProductAndUserAddins(IdeCore.java:1431)
    at oracle.ide.IdeCore.startupImpl(IdeCore.java:1196)
    at oracle.ide.Ide.startup(Ide.java:674)
    at oracle.ideimpl.Main.start(Main.java:49)
    at oracle.ideimpl.Main.main(Main.java:25)
    Does not look right to me.
    I've never tried to add a DB connection under this IDE installation earlier.
    Just yeasterday I've created a project with some DB related (mySQL and Hibernate) libraries, although it compiled fine.

  • Conversion of nvarchar2 to varchar from oracle to postgres.

    Hi,
    I am loading data from oracle to postgres through odi 11g.
    I have a table in oracle whose columns have nvarchar2 datatype and its corresponding in postgres is varchar.
    But when these columns contain null values then the odi is giving an error of unknown type values when loading to postgres and when the data is other then null then the data is getting loaded without a problem.
    Also there is no not null constraint present on the postgres or oracle level.
    Then why the null data is not getting transfer to the postgres through odi 11g.
    Please suggest.

    Hi,
    Why don't you extract using the spool command in SQL Plus and load using SQL Loader.
    something like
    sqlplus scott/tiger
    spool emp.txt
    select col1 &#0124; &#0124; "<ec>", col2 &#0124; &#0124; "<er>" from emp;
    <ec> = end of column
    <er> = end of record
    SQL Loader control file
    load data
    infile 'emp.txt' "str '<er>'"
    into table emp
    fields terminated by '<ec>'
    (column1,
    column2,
    null

  • Returning array of values from a PL/SQL stored procedure

    I try to run the following example, always happen errors: Run-time error'91' Object variable or With block variable not set.(in line: Set myRS.Source = myCmd1 and Set myRS.Source = myCmd2) Who can tell me where is wrong? I check variable, all set.
    Option Explicit
    Dim myCnn As ADODB.Connection
    Dim myCmd1 As ADODB.Command
    Dim myCmd2 As ADODB.Command
    Dim myRS As ADODB.Recordset
    Dim myConnStr As String
    Dim mySQL As String
    Dim inputssn As Long
    Private Sub cmdGetEveryone_Click()
      Dim myLine As String
      Set myRS.Source = myCmd1
      myRS.Open
      myLine = ""
      While Not myRS.EOF
          myLine = myLine & myRS.AbsolutePosition & " " & _
                   myRS(0) & ", " & myRS(1) & ", " & myRS(2) & vbCrLf
          myRS.MoveNext
      Wend
      MsgBox myLine
      myRS.Close
    End Sub
    Private Sub cmdGetOne_Click()
      Set myRS.Source = myCmd2
      inputssn = InputBox("Enter the SSN you wish to retrieve:")
      myCmd2(0) = inputssn
      myRS.Open
      If myRS.RecordCount = 0 Then
         MsgBox "No data found"
      Else
         MsgBox "Person data: " & myRS(0) & ", " & myRS(1) & ", " & myRS(2)
      End If
      myRS.Close
    End Sub
    Private Sub Form_Load()
      'Using an "On-the-fly" nameless ODBC connection
      'Replace <User ID>, <Password>, and <Server> with the
      'appropriate parameters.
      '  myConnStr = "UID=*****;PWD=*****;driver=" _
      '         & "{Microsoft ODBC for Oracle};SERVER=dseOracle;"
      ' myConnStr = "UID=CSUPerson;pwd=euclid;driver={Microsoft ODBC for Oracle};SERVER=company;"
      'you may also use a named connection DSN such as "myOracleODBC" as follows
      myConnStr = "user id=csuperson;password=euclid;DSN=myOracleODBC;"
      Set myCnn = New ADODB.Connection
      With myCnn
          .ConnectionString = myConnStr
          .CursorLocation = adUseClient
          .Open
      End With
      'the entry RESULTSET 99 indicates the arguments (ssn, fname, lname)
      'are arrays of up to 99 cells each.
      'The binding vars (ssn, fname, lname) should be retrieved in VB using a recordSet
      mySQL = "{call packperson.allperson({RESULTSET 99, ssn, fname, lname})}"
      Set myCmd1 = New ADODB.Command
      With myCmd1
          Set .ActiveConnection = myCnn
          .CommandText = mySQL
          .CommandType = adCmdText
      End With
      mySQL = "{call packperson.oneperson(?,{RESULTSET 2, ssn, fname, " _
             & "lname})}"
      Set myCmd2 = New ADODB.Command
      With myCmd2
          Set .ActiveConnection = myCnn
          .CommandText = mySQL
          .CommandType = adCmdText
          .Parameters.Append .CreateParameter(, adInteger, adParamInput)
      End With
      Set myRS = New ADODB.Recordset
      With myRS
          .CursorType = adOpenStatic
          .LockType = adLockReadOnly
      End With
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
      myCnn.Close
      Set myCnn = Nothing
      Set myCmd1 = Nothing
      Set myCmd2 = Nothing
      Set myRS = Nothing
    End Sub
    Package:
    PACKAGE packperson AS
    TYPE tssn is TABLE of NUMBER(10)
    INDEX BY BINARY_INTEGER;
    TYPE tfname is TABLE of VARCHAR2(15)
    INDEX BY BINARY_INTEGER;
    TYPE tlname is TABLE of VARCHAR2(20)
    INDEX BY BINARY_INTEGER;
    PROCEDURE allperson
    (ssn OUT tssn,
    fname OUT tfname,
    lname OUT tlname);
    PROCEDURE oneperson
    (onessn IN NUMBER,
    ssn OUT tssn,
    fname OUT tfname,
    lname OUT tlname);
    END packperson;
    BODY:
    PACKAGE BODY packperson
    AS
    PROCEDURE allperson
    (ssn OUT tssn,
    fname OUT tfname,
    lname OUT tlname)
    IS
    CURSOR person_cur IS
    SELECT ssn, fname, lname
    FROM employee;
    percount NUMBER DEFAULT 1;
    BEGIN
    FOR singleperson IN person_cur
    LOOP
    ssn(percount) := singleperson.ssn;
    fname(percount) := singleperson.fname;
    lname(percount) := singleperson.lname;
    percount := percount + 1;
    END LOOP;
    END;
    PROCEDURE oneperson
    (onessn IN NUMBER,
    ssn OUT tssn,
    fname OUT tfname,
    lname OUT tlname)
    IS
    CURSOR person_cur IS
    SELECT ssn, fname, lname
    FROM employee
    WHERE ssn = onessn;
    percount NUMBER DEFAULT 1;
    BEGIN
    FOR singleperson IN person_cur
    LOOP
    ssn(percount) := singleperson.ssn;
    fname(percount) := singleperson.fname;
    lname(percount) := singleperson.lname;
    percount := percount + 1;
    END LOOP;
    END;
    END;DB table:
    CREATE TABLE EMPLOYEE
    (FNAME VARCHAR2(15) NOT NULL,
    MINIT    CHAR,
    LNAME VARCHAR2(15) NOT NULL,
    SSN VARCHAR2(9) NOT NULL,
    BDATE DATE,
    ADDRESS VARCHAR2(30),
    SEX CHAR,
    SALARY NUMBER(10,2),
    SUPERSSN VARCHAR2(9),
    DNO NUMBER NOT NULL,
    PRIMARY KEY(SSN));
    DESC EMPLOYEE;
    INSERT INTO EMPLOYEE VALUES
    ('John','B', 'Smith', '123456789','09-JAN-65',
      '731 fONDREN, hOUSTON, TX', 'M', 30000, '333445555',5);
    INSERT INTO EMPLOYEE VALUES
    ('Frankin','T', 'Wong', '333445555','08-DEC-55',
      '683 Voss, Houston,Tx', 'M', 40000, '888665555',5);
    INSERT INTO EMPLOYEE VALUES
    ('Alicia','J', 'Zelaya', '999887777','19-JUL-68',
      '3321Castle, Spring, TX', 'F',25000 , '987654321',4);
    INSERT INTO EMPLOYEE VALUES
    ('Jennifer','S', 'Wallace', '987654321','20-JUN-41',
      '291 Berry, Bellaire, TX', 'F',43000 , '888665555',4);
    INSERT INTO EMPLOYEE VALUES
    ('Ramesh','K', 'Narayan', '666884444','15-SEP-62',
      '975 Fire Oak, Humble, TX', 'F',38000 , '333445555',5);
    INSERT INTO EMPLOYEE VALUES
    ('Joyce','A', 'English', '453453453','31-JUL-72',
      '5631 Rice,Houston,TX', 'F',25000 , '333445555',5);
    INSERT INTO EMPLOYEE VALUES
    ('Ahmad','V', 'Jabbar', '987987987','29-MAR-69',
      '980 Dallas,Houston, TX', 'M',25000 , '987654321',4);
    INSERT INTO EMPLOYEE VALUES
    ('James','E', 'Borg', '888665555','10-NOV-37',
      '450 Stone, Houston, TX', 'M',55000 , null,1);All help I will appreciat it.

    I can't comment on the problem returning PL/SQL arrays, but I will suggest that a more appropriate method of achieving your goal is to call a procedure which returns a REF CURSOR.
    See the examples here:
    http://asktom.oracle.com/~tkyte/ResultSets/index.html

  • Error while Shell executing from Oracle Using java proc

    Hi All,
    After a long time I'm here again.
    I'm facing one strange problem.
    SQL>
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Elapsed: 00:00:00.01
    SQL>
    SQL>And, the purpose of this procedure is to execute shell command from PL/SQL application.
    It seems that this procedure is able to execute shell commands like *'pwd'*.
    But, when it comes to other commands like *'ls -lrt'* or *'sqlldr'* it throws error.
    Kindly find the following details -
    SQL> declare
      2    err_cd   number;
      3    err_desc varchar2(500);
      4  begin
      5   dbms_java.set_output(1000000);
      6   host(p_command => '/a/mis/Sqlloader_script/loader_command/ST_det.sh');
      7   dbms_output.put_line('Successfully Executed SQL Loader Command');
      8  exception
      9      when others then
    10        err_cd := 1;
    11        err_desc := substr(sqlerrm,1,500);
    12        dbms_output.put_line(err_desc);
    13  end;
    14  /
    Process err :/a/mis/Sqlloader_script/loader_command/ST_det.sh: line 19: sqlldr: No such file or directory
    Successfully Executed SQL Loader Command
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.11
    SQL>
    SQL> declare
      2    err_cd   number;
      3    err_desc varchar2(500);
      4  begin
      5   dbms_java.set_output(1000000);
      6   host(p_command => 'pwd');
      7   dbms_output.put_line('Successfully Executed SQL Loader Command');
      8  exception
      9      when others then
    10        err_cd := 1;
    11        err_desc := substr(sqlerrm,1,500);
    12        dbms_output.put_line(err_desc);
    13  end;
    14  /
    Process out :/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs
    Successfully Executed SQL Loader Command
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.11
    SQL>But, the file exists in the following path -
    SQL> !ls -lrt /a/mis/Sqlloader_script/loader_command/ST_det.sh
    -rwxrwxr-x 1 oracle root 1315 Apr 13 13:40 /a/mis/Sqlloader_script/loader_command/ST_det.shAny idea?
    Where is the privileges that i need to give to the current user?
    When i directly execute the Sql Loader from the oracle o/s - it ran successfully.
    [oracle@pult loader_command]$ /a/mis/Sqlloader_script/loader_command/ST_det.sh
    SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 13 14:59:19 2012
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Commit point reached - logical record count 64
    Commit point reached - logical record count 128
    Commit point reached - logical record count 192
    Commit point reached - logical record count 256
    Commit point reached - logical record count 320
    Commit point reached - logical record count 384
    Commit point reached - logical record count 448
    Commit point reached - logical record count 512
    Commit point reached - logical record count 576
    Commit point reached - logical record count 640
    Commit point reached - logical record count 704
    Commit point reached - logical record count 732
    Succesful execution of Loading.
    [oracle@pult loader_command]$
    [oracle@pult loader_command]$Thanks in advance.

    This is a generic java proc.
    It works well with windows.
    But, facing this problem in Linux.
    Procedure looks like -
    create or replace and compile java source named host as
    import java.io.*;
    public class Host {
      public static void executeCommand(String command) {
        try {
          String[] finalCommand;
          if (isWindows()) {
            finalCommand = new String[4];
            finalCommand[0] = "C:\\windows\\system32\\cmd.exe";  // Windows XP/2003
            finalCommand[1] = "/y";
            finalCommand[2] = "/c";
            finalCommand[3] = command;
          else {
            finalCommand = new String[3];
            finalCommand[0] = "/bin/bash";
            finalCommand[1] = "-c";
            finalCommand[2] = command;
          final Process pr = Runtime.getRuntime().exec(finalCommand);
          pr.waitFor();
          new Thread(new Runnable(){
            public void run() {
              BufferedReader br_in = null;
              try {
                br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                String buff = null;
                while ((buff = br_in.readLine()) != null) {
                  System.out.println("Process out :" + buff);
                  try {Thread.sleep(100); } catch(Exception e) {}
                br_in.close();
              catch (IOException ioe) {
                System.out.println("Failed to print.");
                ioe.printStackTrace();
              finally {
                try {
                  br_in.close();
                } catch (Exception ex) {}
          }).start();
          new Thread(new Runnable(){
            public void run() {
              BufferedReader br_err = null;
              try {
                br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
                String buff = null;
                while ((buff = br_err.readLine()) != null) {
                  System.out.println("Process err :" + buff);
                  try {Thread.sleep(100); } catch(Exception e) {}
                br_err.close();
              catch (IOException ioe) {
                System.out.println("Process error.");
                ioe.printStackTrace();
              finally {
                try {
                  br_err.close();
                } catch (Exception ex) {}
          }).start();
        catch (Exception ex) {
          System.out.println(ex.getLocalizedMessage());
      public static boolean isWindows() {
        if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
          return true;
        else
          return false;
    };Looking for your reply.

  • Passing Opaque Objects from Oracle to Java

    Hi all
    I am trying to write a stored procedure that needs to be called from different triggers. Each triggers needs to pass a different set of data to the stored procedure. Now the problem is that i need to pack the different set of data into one opaque object type that i can pass onto java. Is there any way of doing this. I am using Oracle 9i running on Linux 2.4.9. I tried using the Object datatype in Oracle 9i. But am not able to pass a object datatype to java directly.

    Didn't know that. Guess the way this API handles the struct is it puts it on the heap, since this idea (with passing a 32-bit var back and forth with a memory location) worked.
    My next problem - I can't figure out a way to destroy a jstring: whenever I do an env->GetStringUTF((char*)charBuff), it seems to simply copy the bytes from the buffer
    into the same String object up the length of the buff (so I get the extra bytes from the previous String if it was longer at the end).
    Here's how it works: I have a loop in C code that parses tags inside a file, then depending on what tag it is, I create a new jobject and call a Java method to do stuff
    to that object. As one of the parameters in the constructor I pass in a String that I create (as you can see above) from a character array, however I am getting
    massive artifacts when I print out that String inside the Java method.
    Thoughts? :(

  • Save Attachment from exchange server 2010 from oracle using java mail API

    Hello,
    I want to read email from microsoft exchangeserver 2010 and save attachement into a folder.I created an Java program to import attachments from a exchange server mailbox using "POP3S".It works fine when run as a java application.But when i put this inside Oracle11g R2 using load java and while executing from a procedure it gives an error at parsing message into Multipart
    Error at line : Multipart mp = (Multipart)m.getContent();
    Error:
    Content-Type: multipart/mixed;
    boundary="_002_A0C2E09A..................................."
    java.lang.ClassCastException
    at mailPop3.checkmail(mailPop3:71)
    My Java Class is as follows,
    import java.io.*;
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.Date;
    The function i used to check for attachments is given below.
    public static boolean hasAttachments(Message m) throws java.io.IOException, MessagingException
    Boolean hasAttachments = false;
    try
    // if it is a plain/html text - no attachements
    if (m.isMimeType("text/*"))
    return hasAttachments;
    else if (m.isMimeType("multipart/alternative"))
    return hasAttachments;
    else if (m.isMimeType("multipart/*"))
    Multipart mp = (Multipart)m.getContent();
    if (mp.getCount() > 1)
    hasAttachments = true;
    return hasAttachments;
    catch (Exception e) {
    e.printStackTrace();
    } finally {
    return hasAttachments;
    My Java Details as follows
    java Version :1.5.0_10
    java.vm.specification.version:1.0
    java.vm.version :1.5.0_01
    java.specification.version:1.5
    java.class.version:48.0
    Java mail API:javamail-1.4.4
    Used Jars:mail.jar
    Could someone explain why I am getting this error? What can I do to resolve this error?
    Is any other Jar need other than mail.jar?
    Any help would be much appreciated.
    Regards,
    Nisanth

    Hai EJP,
    Thanks for your reply,
    My full java class as follows,
    import java.util.Properties;
    import javax.mail.Authenticator;
    import javax.mail.Folder;
    import javax.mail.Message;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Store;
    import javax.mail.Part;
    import javax.mail.Multipart;
    import javax.mail.internet.MimeMultipart;
    import javax.mail.internet.MimeMessage;
    public class Newmail
    public Newmail()
    super();
    public static int mailPOP3(String phost,
    String pusername,
    String ppassword)
    Folder inbox =null;
    Store store =null;
    int result = 1;
    try
    String host=phost;
    final String username=pusername;
    final String password=ppassword;
    System.out.println("Authenticator");
    Authenticator auth=new Authenticator()
    protected PasswordAuthentication getPasswordAuthentication()
    return new PasswordAuthentication(username, password);
    System.out.println("Certificate");
    String filename="D:\\Certi\\jssecacerts";
    String password2 = "changeit";
    System.setProperty("javax.net.ssl.trustStore",filename);
    System.setProperty("javax.net.ssl.trustStorePassword",password2);
    Properties props = System.getProperties();
    System.out.println("host-----"+props);
    props.setProperty("mail.pop3s.port", "993");
    props.setProperty("mail.pop3s.starttls.enable","true");
    props.setProperty("mail.pop3s.ssl.trust", "*");
    Session session = Session.getInstance(props,auth);
    session.setDebug(true);
    store = session.getStore("pop3s");
    System.out.println("store------"+store);
    store.connect(host,username,password);
    System.out.println("Connected...");
    inbox = store.getDefaultFolder().getFolder("INBOX");
    inbox.open(Folder.READ_ONLY);
    Message[] msgs = inbox.getMessages();
    System.out.println("msgs.length-----"+msgs.length);
    result = 0;
    int no_of_messages = msgs.length;
    for ( int i=0; i < no_of_messages; i++)
    System.out.println("msgs.count-----"+i);
    System.out.println("Attachment....>"+msgs.getContentType());
    Multipart mp = (Multipart)msgs[i].getContent();
    System.out.println("Casting Success" + mp.getContentType());
    catch(Exception e)
    e.printStackTrace();
    finally
    try
    if(inbox!=null)
    inbox.close(false);
    if(store!=null)
    store.close();
    return result;
    catch(Exception e)
    e.printStackTrace();
    return result;
    Please check it
    Regards,
    Nisanth

  • Pass an array of integers from C to Java with JNI

    Hello,
    I have a C function that returns a struct me. The fields of this struct are all of type integer. I, with the fields of this structure create an array of integers in C language I would like to pass this array of integers c, in Java using JNI.
    How can I make this?

    I don't see how you compiled that.
    It certainly will not compile for me.
    jintArray position=(jintArray)(*env)->NewIntArray(env,2);That is the invocation idiom for C code.
    jint f[2];You cannot have a variable declaration in the middle of a method (block) in C code. That is only allowed in C++.
    C code and C++ code is not the same.
    The following is C++ code. Note that it does NOT include getBinaryPoint() since that method could be the source of the problem.
    jintArray position = env->NewIntArray(2);
    if(position==NULL)     return NULL;
    jint f[2];
    f[0]=3;
    f[1]=4;
    env->SetIntArrayRegion(position,0,2,f);
    return position;

  • Losing precision coming from Oracle to Java

    30.20969963 is becoming 30.
    The field is an Oracle Number datatype and I am using a Number in Java. Obviously that isn't right - what data type in Java will preserve all of the decimal places the database has?
    Thanks!!

    BigDecimal.
    By the way there is a JDBC forum which would probably be a better place for all database related questions.

  • Return type Boolean From Oracle Function

    1. How do I get a return type of Boolean from Oracle function in Java?
    2. I have a function fx overloaded in Oracle (8 variances) and I have trouble getting the right one in Java. Is 8 too high a figure or Java does not support calling overloaded functions or what?
    Thanks for any help.

    I am facing a similar situation, where I have defined an overloaded function in one package (2 variants) which both return a type BOOLAN value.
    I am having trouble to setting up an CallableStatemnt to call one of this functions from Java. Whenever I set the parameter with a BIT or NUMBER data type, I get an exception with java.lang.boolean during my
    callablestatement.setobject( indez, parameter, OracleTypes.BIT );
    or
    callablestatement.setobject( indez, parameter, OracleTypes.NUMBER );
    I have no problem calling the function from SQLPlus, but doing so from Java raises the exception. I have found no exact match in OracleTypes or java.sql.Types for a BOOLEAN data type.
    In your response do you mean to modify the Function to return a NUMBER instead of a BOOLEAN, or do you mean to set the parameter as Types.NUMBER in the calling java code?
    Thanks,
    Fedro

  • Return array from Procedure

    can any one please tell me how to pass an dynamic array to a Procedure and get an dynamic array of values from Oracle.
    Thanks,
    Prasenjit

    PROCEDURE sp_error_report_summary(errorDate IN VARCHAR,
                                      RESULT1   OUT Types.ref_cursor,
                                      RESULT2   OUT Types.ref_cursor,
                                      RESULT3   OUT Types.ref_cursor) IS
        error_cursor Types.ref_cursor;
    BEGIN
        OPEN RESULT1 FOR
            SELECT error_message,
                   site_name,
                   COUNT(*) COUNT_MSG
            FROM   error_report
            WHERE  error_date = errorDate
            GROUP  BY error_message,
                      site_name
            ORDER  BY site_name;
        OPEN RESULT2 FOR
            SELECT * FROM registration;
        OPEN RESULT3 FOR
            SELECT * FROM category;
    END;

  • Stored Procedure: Function returns Array

    I was just wondering if following scenario is possible in a stored procedure.
    I have a package, which includes 4 different functions and 1 procedure. Procdure uses ref cursor to return values in my reporting tool. What I am trying to do is to write a function which takes input and return array of varchar. Something like..
    Package ABC
    Function student_classes (student_no in Varchar2) return [array]
    begin
    select class_nbr into [array]
    from student_table
    where student_nbr = student_no;
    return [array];
    end student_classes;
    procedure students_info (rpt_cursor IN OUT rpt_type)
    begin
    OPEN rpt_cursor FOR
    select
    student_name,
    student_nbr,
    student_address,
    student_classes (student_nbr) --returns array
    from student_table;
    end student_info; --end of procedure
    end abc; --end of pacakge.
    I used [array], as I am ont sure how to define (syntax) it in spec part of package or in body. I will really appreciate if someone could help me with this function.
    Thank you

    Thanks for the reply Tonguc Y.
    I declared an array in my package declaration
    CREATE OR REPLACE PACKAGE rpt_TESTING_pkg
    AS TYPE rpt_type IS REF CURSOR;
         TYPE DIAGARRAY IS VARRAY(20) OF VARCHAR2(6);
         FUNCTION DIA_CODES (MNO IN VARCHAR2) RETURN DIAGARRAY;
         PROCEDURE member (rpt_cursor IN OUT rpt_type);
    END rpt_TESTING_pkg;
    but then when I try to use it in my function it gives me error that I should declare DIAGARRAY.
    CREATE OR REPLACE PACKAGE BODY rpt_TESTING_pkg
    as
    FUNCTION DIA_CODES (MNO IN VARCHAR2)
                   RETURN DIGARRAY AS diags DIGARRAY;
    begin
    <sql block>
    end dia_codes;
    end rpt_TESTING_pkg;
    Any suggestions.

  • Problem returning array of strings

    Hi,
    I am trying to return an array of strings from C to Java.The function I am using is
    char rec[20][20];
    int num=0;
    /* incrementing num and copying into the array everytime a record is added*/
    JNIEXPORT jobjectArray JNICALL Java_jnimidlet_list_1rec
    (JNIEnv *env, jobject obj)
    jstring str;
    jobjectArray args = 0;
    jsize len = num;
    int i=0;
    args = (*env)->NewObjectArray(env, len,
    (*env)->FindClass(env, "java/lang/String"), 0);
    for( i=0; i < len; i++ )
    str = (*env)->NewStringUTF( env, rec);
    (*env)->SetObjectArrayElement(env, args, i, str);
    return args;
    In the java code:
    String []all=list_rec();
    when this function is called I get the error:
    Unhandled exception
    Type=GPF vmState=0xffffffff
    ExceptionCode=0xc0000005 ExceptionAddress=0x00000000 ContextFlags=0x0001003f
    Handler1=0x10f01530 Handler2=0x10026280
    Module=C:\wsdd5.5\wsdd5.0\ive\bin\j9.exe
    Module_base_address=0x00000000
    Offset_in_DLL=0x00000000
    EDI=0x0012fc14 ESI=0x10f01530 EAX=0x00020020
    EBX=0x00148e34 ECX=0x0017469c EDX=0x00020020
    EBP=0x00149d40 ESP=0x0012fbec EIP=0x00000000
    Thread: main (priority 5) (LOCATION OF ERROR)
    Thread: Gc Thread (priority 5) (daemon)
    Can anyone pls tell me how do I come out of this problem.
    Please help.
    Thanx in advance,
    pri_rav

    Hi Priya,
    I dont see any problem. I tried to work with your code it works fine without any exception. Please make sure all ur rec char buff contents are null terminated and your 'i' counter is initialized properly and stops properly. According to me there shouldn't be any problem with JVM. I hope you are aware of c programming,which doesn't check for array boundaries. You may accidentally go out of array size allocated. So my suggession is to check you rec buff going above any of the dimension. Put a watch on 'i' variable content as well. Try and let me know whether it solves your problem. If it doesn't reply me with more details. I will try helping you.
    Thanks,
    Regards,
    Ravikiran.

Maybe you are looking for

  • LSO: Business Event Appraisal

    Hi, We have already implemented LSO.Now we are planning to configure Appraisal for a Business Event. Please do share any docs related to the configuration Thanks in advance. Regards, Deb

  • Plant restriction at sales order level by user

    Dear SD experts, Is it possible to restrict plant at sales order creation by user, if so, how this is to be configured. my requirement is user shall not able to create sales order(sales document) for plants restricted. pl help thanx in advance regard

  • Creating a Form Template Questions

    Can I create a form? Meaning, can I create a document that has blanks (underscored blank spaces) that I can later edit to contain information/answers? i.e. Name: ______ Address: _______ Then, if I can what is the best way to make it so that it is don

  • How do I fix iMac that automatically ejects disks without reading them

    How do I fix an iMac that automatically ejects disks without reading them? Have tried resetting the SMC, didn't work. If I have to get a new drive, how much do they cost on an iMac and where do I get it fixed?  Very disappointed if we have to spend m

  • To change the classification data for a material using BDC

    I have to update clssification data for material in MM02 using BDC so when i record the transaction MM02 using SHDB i am not able to see the value assignment window which i a able to see when i am changing using MM02 transaction directly. So can anyo