Calling a SP or Function from Java receiving a geometry(MDSYS.SDO_GEOMETRY)

Hi there,
What I want to do is: calling a stored procedure OR function from Java with a String-variable as input and receiving a geometry (SDO_GEOMETRY).
I’m facing currently the problem of calling a stored function on oracle 11g from Java using JPA (EclipseLink), Spring 2.5.6 returning an MDSYS.SDO_GEOMETRY object.
I’ve tried to call a stored procedure with MDSYS.SDO_GEOMETRY as an output parameter instead, but with no success.
The function’s signature looks like this:
CREATE or REPLACE
FUNCTION GET_GEO_BRD_FUNCTION(p_geo_brd_id IN VARCHAR2) RETURN MDSYS.SDO_GEOMETRY AS
sdo_geom    MDSYS.SDO_GEOMETRY := null;
BEGIN
/* do some fancy stuff on the database side */
  SELECT sp_geom
    INTO sdo_geom
    FROM geo_brd WHERE id = p_geo_brd_id;
  RETURN sdo_geom;
END;
The calling code looks like this:
MyClass extends JpaDaoSupport{
   /** logger */
   protected static final ILogger LOG = LogFactory.getLogger(MyClass.class);
    * {@inheritDoc}
    * @see com.example.MyClass#calculateGeometry(java.lang.String)
   @Override
   public JGeometry calculateGeometry(final String id) {
       JGeometry geometry = null;
       final JpaCallback action = new JpaCallback() {
            @Override
            public Object doInJpa(final EntityManager em) throws PersistenceException {
               final Session session = JpaHelper.getEntityManager(em).getActiveSession();
               final StoredFunctionCall functionCall = new StoredFunctionCall();
               functionCall.setProcedureName("GET_GEO_BRD_FUNCTION");
               functionCall.addNamedArgument("p_geo_brd_id");
               functionCall.setResult("sdo_geom", Oracle.sql.STRUCT.class);
               final ValueReadQuery query = new ValueReadQuery();
               query.setCall(functionCall);
               query.addArgument("p_geo_brd_id");
               final ArrayList args = new ArrayList();
               args.add("2e531e62-2105-4522-978a-ab8baf19e273");// hardcoded for test
               final Object result = session.executeQuery(query, args);
               return result;
    final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);
    try {
       geometry = JGeometry.load(result);
    } catch (final SQLException e) {
       MyClass.LOG.error("Error loading JGeometry from STRUCT.", e);
       return null;
    return geometry;
And when I execute the query I get the following error:
Internal Exception: java.sql.SQLException: ORA-06550: Row 1, Column 13:
PLS-00382: expression is of wrong type
ORA-06550: Row 1, Column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call: BEGIN ? := GET_GEO_BRD_FUNCTION(p_geo_brd_id=>?); END;
     bind => [=> sdo_geom, 2e531e62-2105-4522-978a-ab8baf19e273]
Query: ValueReadQuery()
So I thought may be let's try it with a stored procedure instead...
The procedure looks like this:
CREATE or REPLACE
PROCEDURE GET_GEO_BRD_PROCEDURE(p_geo_brd_id IN VARCHAR2, sdo_geom OUT MDSYS.SDO_GEOMETRY) AS
BEGIN
/* do some fancy stuff on the database side */
  SELECT sp_geom
    INTO sdo_geom
    from geo_brd where id = p_geo_brd_id;
END;
The calling Java code in case of the stored procedure looks like this (only the content of the JPACallback has changed):
@Override
public Object doInJpa(final EntityManager em) throws PersistenceException {
    final Session session = JpaHelper.getEntityManager(em).getActiveSession();
    final StoredProcedureCall spCall = new StoredProcedureCall();
    spCall.setProcedureName("GET_GEO_BRD_PROCEDURE");
    spCall.addNamedArgument("p_geo_brd_id", "p_geo_brd_id", String.class);
    spCall.addNamedOutputArgument("sdo_geom", "sdo_geom", OracleTypes.STRUCT);
    final ValueReadQuery query = new ValueReadQuery();
    query.setCall(spCall);
    query.addArgument("p_geo_brd_id"); // input
    final List args = new ArrayList();
    args.add("2e531e62-2105-4522-978a-ab8baf19e273");// hardcoded for test
    final Object result = session.executeQuery(query, args);
    return result;
And when I execute the query I get the following error:
java.sql.SQLException: ORA-06550: Row 1, Column 13:
PLS-00306: wrong number or types of arguments in call to 'GET_GEO_BRD_PROCEDURE'
ORA-06550: Row 1, Column 7:
PL/SQL: Statement ignored
So both exceptions look quite similar.
I guess in both cases the exception description leads to the assumption, that the wrong type for the return value / output parameter is used…
So - how can a receive a MDSYS_SDO_GEOMETRY object from a stored procedure or stored function in Java ?
What is wrong in the Java code?
Thank you in advance for any suggestions!
Yours,
Chris
Edited by: user3938161 on 20.12.2011 07:46
Edited by: user3938161 on Dec 20, 2011 8:06 AM: added variable declaration of JGeometry geometry in source code

Thanks, that did the trick! ;-)
Here is now the code for stored procedure and function for anybody else encountering the same troubles... (be aware of the parameter order and/or naming!)
Code for stored functions:
final JpaCallback action = new JpaCallback() {
  @Override
  public Object doInJpa(final EntityManager em) throws PersistenceException {
     final Session session = JpaHelper.getEntityManager(em).getActiveSession();
       * Using CallableStatement for stored functions
      STRUCT st = null;
      CallableStatement cs = null;
      final DatabaseLogin login = session.getLogin();
      final Connection _conn = (Connection) login.connectToDatasource(session.getDatasourceLogin().buildAccessor(), session);
      try {
         try {
            cs = _conn.prepareCall("{? = call GET_GEO_BRD_FUNCTION(?)}");
            cs.registerOutParameter(1, OracleTypes.STRUCT, "MDSYS.SDO_GEOMETRY");
            cs.setString(2, "2e531e62-2105-4522-978a-ab8baf19e273");//TODO: hardcoded for test
            cs.execute();
         } catch (final SQLException e) {
            MyClass.LOG.error("An exception occured calling the stored procedure", e);
         if (cs != null) {
            //reading geometry from the database
            try {
               st = (STRUCT) cs.getObject(1);
            } catch (final SQLException e) {
               MyClass.LOG.error("An exception occured converting the query result to oracle.sql.STRUCT", e);
      } finally {
         try {
            if (_conn != null && !_conn.isClosed()) {
                _conn.close();
         } catch (final SQLException e) {
            MyClass.LOG.error("An exception occured on closing the database connection.", e);
      return st;
final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);
The code for stored procedure solution:
final JpaCallback action = new JpaCallback() {
  @Override
  public Object doInJpa(final EntityManager em) throws PersistenceException {
      final Session session = JpaHelper.getEntityManager(em).getActiveSession();
       * Using CallableStatement for stored procedure
      STRUCT st = null;
      CallableStatement cs = null;
      final DatabaseLogin login = session.getLogin();
      final Connection _conn = (Connection) login.connectToDatasource(session.getDatasourceLogin().buildAccessor(), session);
      try {
         try {
            cs = _conn.prepareCall("{call GET_GEO_BRD_PROCEDURE(?,?)}");
            cs.setString("p_geo_brd_id", "2e531e62-2105-4522-978a-ab8baf19e273");
            cs.registerOutParameter("sdo_geom", OracleTypes.STRUCT, "MDSYS.SDO_GEOMETRY");
            cs.execute();
          } catch (final SQLException e) {
            MyClass.LOG.error("An exception occured calling the stored procedure", e);
          if (cs != null) {
            //reading geometry from the database
            try {
               st = (STRUCT) cs.getObject("sdo_geom");
            } catch (final SQLException e) {
               MyClass.LOG.error("An exception occured converting the query result to oracle.sql.STRUCT", e);
       } finally {
          try {
            if (_conn != null && !_conn.isClosed()) {
               _conn.close();
          } catch (final SQLException e) {
            MyClass.LOG.error("An exception occured on closing the database connection.", e);
        return st;
final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);

Similar Messages

  • Calling a PL/SQL function from java

    I would like to call a pl/sql function from java. My pl/sql function is taking arrays of records as parameters. How do i proceed? Which specific oracle packages do I have to import?
    Please send an example.
    TIA,
    Darko Guberina

    Documentation here: http://download-uk.oracle.com/docs/cd/B14117_01/java.101/b10983/datamap.htm#sthref185
    says JPublisher can publish records too.
    But when I change the example given at http://download-uk.oracle.com/docs/cd/B14117_01/java.101/b10983/datamap.htm#sthref190 as following:
    PACKAGE "COMPANY" AS
    type emp_rec is record (empno number, ename varchar2(10));
    type emp_list is varray(5) of emp_rec;
    type factory is record (
    name varchar(10),
    emps emp_list
    function get_factory(p_name varchar) return factory;
    END;
    then I see <unknown type or type not found> at sql or java files generated. Any ideas?

  • Calling Window's Dll Functions from Java

    Hello Audience,
    Is there a way to call Win32/64 based Dynamic-Link-Library functions from Java?
    Thanks,
    GenKabuki

    Yes.
    In general, if you are trying to call functions in an existing dll, you will have to write a "wrapper" dll that meets the java jni interface requires. There are tools around wich purport to generate these for you. Do a google serach; among other tools, you should turn up JACE.

  • CALLING a STORED SQL FUNCTION from  Java 1.1.8

    I am trying to execute a stored function in JAVA 1.1.8, from an Oracle
    8i Database. My stored function is simple, it converts an Input Number to an output TIME string. I am unsure how to code the call from Java. Are SQL STORED PROCEDURES treated the same as SQL STORED FUNCTIONS? Do you use the CallableProcdure class or something else?
    Thanks for your input.

    yep - same way. Except no return value.

  • Calling OCI functions from Java

    Is it possible to call OCI's API functions from Java and create a Lightweight Session ?
    Please help me out.

    I too would like to know how this can be accomplished. I have
    seen several posts that claim it is possible with Oracle91.

  • Error PLS-00306 during calling PL/SQL function from Java

    Hi all,
    I am facing a problem during call of oracle PL/SQL function from java using CallableStatement.
    I receive following error message.
    java.sql.SQLException: ORA-06550: line 1, column 13:
    PLS-00306: wrong number or types of arguments in call to 'EXPORT_HIST_ALARMS_FUNC'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    As per above error EXPORT_HIST_ALARMS_FUNC in oracle has this signature.
    CREATE OR REPLACE FUNCTION EXPORT_HIST_ALARMS_FUNC(startDateTime VARCHAR2, endDateTime VARCHAR2, meType VARCHAR2) RETURN VARCHAR2 IS
    END EXPORT_HIST_ALARMS_FUNC;
    Above function I have called following way in java.
    String sql = "begin ?:= EXPORT_HIST_ALARMS_FUNC(?, ?, ?); end;" ;
    CallableStatement cStatement = null;
    cStatement = connection.prepareCall(sql);
    cStatement.registerOutParameter(1,Types.VARCHAR);
    cStatement.setString(2,startDateTime);
    cStatement.setString(3,endDateTime);
    cStatement.setString(4,meType);
    cStatement.execute();
    msg = cStatement.getString(1);
    Actually above function requires three input parameters and one return parameter.
    During execution of above java code it throws SQLException and shows PLS-00306: wrong number or types of arguments in call to 'EXPORT_HIST_ALARMS_FUNC' error.
    I have run this function directly from oracle with three parameters and run successfully and finally it returns string.
    But I am unable to figure out why it doesn't run from above java code.
    Please help regarding this.
    Thanks.
    Regards,
    Shardul Banker

    Try this:
    String sql = "begin ?:= EXPORT_HIST_ALARMS_FUNC(?, ?, ?); end;" ;
    CallableStatement cStatement = null;
    cStatement = connection.prepareCall(sql);
    cStatement.registerOutParameter(1,Types.VARCHAR);
    cStatement.setString(1,startDateTime);
    cStatement.setString(2,endDateTime);
    cStatement.setString(3,meType);
    cStatement.execute();
    msg = cStatement.getString(1);Regards,
    Martijn Teigeler
    Edited by: mTeigeler on Oct 13, 2007 10:22 AM

  • ORA-00911: invalid character - Calling a function from Java..

    Hi to all.. I have an issue when calling an oracle function from Java..
    This is my Java code:
    final StringBuffer strSql = new StringBuffer();
    strSql.append("SELECT GET_TBL('II_2_1_6_5') AS TABLA FROM DUAL;");
    st = conexion.createStatement();
    rs = st.executeQuery(strSql.toString());
    and in the executeQuery a SQLException is throwed:
    java.sql.SQLException: ORA-00911: invalid character
    I paste the query in TOAD and it works.. :S
    anybody knows how can I solve this?

    Remove the Semicolon after Dual.
    strSql.append("SELECT GET_TBL('II_2_1_6_5') AS TABLA FROM DUAL");
    Sushant

  • Call peoplesoft function from java code

    Can we call the peoplesoft decrypt function from within java code ?

    Hi Sumit,
    For getting the connection, I would use something like:
    import com.sap.mw.jco.JCO;
    public class R3Connector {
         private JCO.Client jcoclient = null;
         public  R3Connector () {
                   super();
         public JCO.Client getClient() {
              if (jcoclient == null) {
                   /* get connection from Pool */
                   jcoclient = JCO.getClient (POOL_NAME);
              return jcoclient;
         public void releaseClient() {
              if (jcoclient != null) {
                   JCO.releaseClient(jcoclient);     
    and of course you will have to define your POOL property somewhere (portalapp.xml presumably)
    Hope this helps!

  • Call DLL function from JAVA

    HI!
    What's the best way (and simple) to call DLL function from JAVA.
    DLL function (developed in C) has two input parameters (string) and return an integer.
    Could you help with an example?
    Thanks a lot.

    Do a google search for 'JNI tutorial' and it will turn up hundreds of examples.

  • Calling c function from java!!

    hi all,
    I want to call c function from java . I have gone through the link http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html for JNI.
    According to this link we need to write the native method implementation in such a way that the method signature should exactly match the method signature created in the header file.
    My problem is that i have a c application which i cannot modify in any ways i.e., i cannot change its code. But i want to call its function from my java code.
    Please suggest me appropriate solution for this. Please let me know whether it can be done using JNI or is there any other method for this.
    thanks

    This link is amazing since those sources were wrote in 1998 and I started to develop JNative in 2004. I did not found them when I started.
    Since JNative can deal with callbacks and probably COM in a near future, I expect to see it living to Dolphin at least.
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Calling an external C function from a C file in JNI

    Hello,
    I am trying to call an external C function, from a C file which is being called by a Java file. I am getting an unresolved symbol error. I have tried many things like, making the external C function in the format of JNI, etc, etc. It is still not working. I think it has something to do with linking the two C files. If anyone can please answer this, it would greatly help me. here is the code:
    HelloWorld.c:
    #include <jni.h>
    #include <stdio.h>
    #include "MyOldHello.h"
    #include "HelloWorld.h"
    JNIEXPORT void JNICALL
    Java_HelloWorld_print(JNIEnv *env, jobject obj)
         helloPrint();
         return;
    HelloWorld.java:
    class HelloWorld
         private native void print();
         public static void main(String[] args)
              new HelloWorld().print();
         static
              System.loadLibrary("HelloWorld");
              System.loadLibrary("MyOldHello");
    MyOldHello.c:
    #include <jni.h>
    #include <stdio.h>
    #include "MyOldHello.h"
    void helloPrint()
         printf("\nHello World!\n");
    MyOldHello.h:
    void helloPrint();
    Now i use the Visual C++ command prompt to compile this by saying:
    javac HelloWorld.java
    javah -jni HelloWorld
    cl -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll
    and now it gives me the error saying that there is an unresolved external symbol, which is the call to helloPrint in the file HelloWorld.
    If anyone knows how to solve this, or how to call external C functions from a C file that is being called from a Java file using JNI, please respond.
    Thanks
    Nick

    Hi,
    In your post on velocity review, you did not compile MyOldHello.c. You compiled a C file that included the header file for it and called a method defined in the header. The linker is never going to be able to find the code for this if you do not include the object file for this.
    Try this. You will also have to add in any JNI libraries you need to link against but I am sure you could work that out.
    cl /c MyOldHello.c
    cl /c -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD HelloWorld.c
    cl /LD MyOldHello.obj HelloWorld.obj /FeHelloWorld.dll
    [http://msdn.microsoft.com/en-us/library/f35ctcxw(VS.80).aspx]
    Cheers,
    Shane

  • Calling a pure C function from JNI method

    Is it posible to call a pure C function from a JNI method.?
    I am communicating with an external device whose API is written in C language.
    Would it work this way
    If I declare empty native methods in Java and those methods in C call pure C methods?
    Thank You...

    Hello,
    I have a similar problem and I posted it here http://www.velocityreviews.com/forums/t724826-jni-calling-an-outside-function-in-the-c-file-which-is-being-called-by-the-java-file.html. If you can answer the question, it would greatly help me.
    Thanks
    Nick

  • Is it possible to call the Print Quote functionality from Custom ADF page

    Hi,
    We are researching if it is possible to call the Print Quote functionality from the Custom ADF application.
    Goal is to pop up the PDF report upon clicking the Print Quote button on the custom page. Is it possible ?
    Atleast advice on the direction to go forward is appreciated.
    Thanks
    Sai

    Hi ,
    Please check following thread on forum -
    Re: ADF: Calling OAF Page from ADF page
    Check this may also be useful-
    https://blogs.oracle.com/shay/entry/to_adf_or_oaf_or
    I have not tried yet but Steven Chan (Sr. Director OATG) suggest following methodolgy for this-
    https://blogs.oracle.com/stevenChan/entry/appsdatasource_jaas_ebs
    Thanks,
    Ashish

  • Without calling stored procedure or functions from database

    Hi,
    I am using Jdeveloper 11.1.1.5.0.
    =>How to do PL/SQL procedures and functions in ADF without calling stored procedure or function from DB?

    S, PL/SQL procedures and functions are done in Application Module class or in managed bean..By calling the stored procedures or functions from DB.
    But I am asking how to do if DB doesn't have any procedures,triggers and functions.

  • Calling native Objective C code from Java Script

    Hi,
    I want to call native objective C code from Java script.
    I know one way by using : webView:shouldStartLoadWithRequest:navigationType
    Is there another way of doing same?
    Thanks,
    Ganesh Pisal
    Vavni Inc

    Are any of those threads calling java code? If yes then are you calling the Attach method?

Maybe you are looking for

  • IPod errors, and won't sync!

    i dropped my iPod (80 GB) a couple of days ago... and when i tried to sync it it froze for a while and then it gave a message saying this: "Attempting to copy to the disk "IPOD" failed. An unknown error occurred (-53)." Along with this other message:

  • Avoiding creation of reservation during creation of production order

    Dear gurus,                  when we create a production order for a semifinshed material there are reservations created for the raw material used to produce the semifinished material ,what if I what to avoid the creation of material reservation . I

  • Forcing to use index

    I have a query which is taking 2 minutes to respond. When I see the explain plan, it said for two tables it is doing the full table scan. So I tried forcing to use the index on the inner tables(xcm, detail) of the views(vw_xcm , vw_vw_detail). But it

  • Embedded double quotes in a quoted string not working.

    It seems that Numbers doesn't process embedded double quotes correctly in a quoted string. Is this an issue that Apple are aware about? Any fixes planned? Is this an issue that Apple are aware about? Any fixes planned? This is not an issue in Excel,

  • Using OCI without SRM

    Hi all, i was asked to verify if it is possible to implement a vendor integration without an SRM Server. The vendor offers a catalog that supports OCI. We want to build a simple prototype that shows the vendors catalog, gets the data from it and proc