ClassCastException in JGeometry.store()

Hi,
I've been struggling with inserting very large polygons into my table from Java.
In order to try to simplify the problem, I used the sample code as suggested from the newsgroup, see below:
double[] coords = new double[10000];
for(int i=0; i<coords.length; i++)
coords[i] = i;
JGeometry mypoly = JGeometry.createLinearPolygon(coords, 2/*dimensions*/, 8256);
PreparedStatement ps = connection.prepareStatement("insert into states (shape) values (?)");
STRUCT obj = JGeometry.store(mypoly, connection);
ps.setObject(1, obj);
ps.execute();
I get this exception on the line which does the JGeometry.store call:
Exception:
java.lang.ClassCastException
at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:128)
at oracle.spatial.geometry.JGeometry.createDBDescriptors(JGeometry.java:1321)
at oracle.spatial.geometry.JGeometry.store(JGeometry.java:1257)
at Test.main(Test.java:43)
I am using an sdoapi.jar that I downloaded from the Oracle website a few days ago and am using ojdbc14.jar.
I'm running Oracle 9.2, JDK 1.4.2, Windows 2000 OS.
Has anyone else been able to do the JGeometry.store() call in java to an Oracle 9.2 db on Windows?
Any suggestions on what to try next?
Thanks,
Erika

where did you get the ojdbc14.jar and what version is it? can you try classes12.jar instead of ojdbc14.jar?

Similar Messages

  • 11g Method -- byte[] JGeometry.store( JGeometry ) fails for certain SQL

    Hi All,
    Using the new in 11g byte[] JGeometry.store( JGeometry ) method as oppose to the traditional STRUCT JGeometry.store( JGeometry, Connection) method fails for certain SQL statements.
    It works fine for statements like this:
    UPDATE PARCELS SET GEOM = ? WHERE ID = 47;
    These statements give errors though:
    UPDATE PARCELS SET GEOM = SDO_MIGRATE.TO_CURRENT( ?, (SELECT DIMINFO FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'PARCELS' AND COLUMN_NAME = 'GEOM') ) WHERE ID = 47;
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'TO_CURRENT'
    SELECT ID, LABEL, GEOM FROM PARCELS WHERE SDO_NN( GEOM, ?, 'SDO_BATCH_SIZE=5000' ) = 'TRUE';
    ORA-29900: operator binding does not exist
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'SDO_NN'
    ? Being where I bind in the byte[] / Object as appropriate.
    So I get the above errors when using setBytes( index,  JGeometry.store( jgeom ) ); but it work when using: setObject( index,  JGeometry.store( jgeom, con ) );
    Is this a bug is known / will be fixed ?
    Thanks,
    Ronan

    Ronan,
    Typically this works fine in OC4J, but does not work in WLS or other containers since the connection type is different between.
    In OC4J, the connection is an Oracle connection which can handle these object conversions.
    We will try to improve the documentation for this to explicitly specify where this interface can be used.
    siva

  • JGeometry / oracle.jdbc.OracleDriver ClassCastException

    Hi-
    I can't seem to store my JGeometry (from the SDO API) back to the database. The code that causes the problem is this:
    ===== Sample Code ========
    import oracle.jdbc.OracleConnection;
    OracleConnection oc = (OracleConnection) st.getConnection();
    STRUCT struct = JGeometry.store((JGeometry)value,oc);
    ==========================
    That last line of code throws this error:
    ===== Exception ============
    05/01/04 16:50:26 [ERROR] ResultForm - Could not save the ResultBean <java.lang.ClassCastException>java.lang.ClassCastException
         at oracle.jdbc.driver.OracleConnection.unwrapCompletely(OracleConnection.java:5075)
         at oracle.jdbc.driver.OracleConnection.physicalConnectionWithin(OracleConnection.java:5126)
         at oracle.sql.TypeDescriptor.setPhysicalConnectionOf(TypeDescriptor.java:494)
         at oracle.sql.TypeDescriptor.<init>(TypeDescriptor.java:147)
         at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:186)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:118)
         at oracle.spatial.geometry.JGeometry.createDBDescriptors(JGeometry.java:1323)
         at oracle.spatial.geometry.JGeometry.store(JGeometry.java:1257)
         at gov.usgswim.wdnr.fishform.GeometryType.nullSafeSet(GeometryType.java:54)
    =========================
    It looks like the oracle.jdbc.driver.OracleConnection.unwrapCompletely method is assuming the connection to be something that it is not - but I'm stumped without the source code.
    I've seen someone speculate that this is a classloader issue, but I'd have no idea how to resolve that within OC4J.
    Here is my setup:
    Running from JDev 9.0.5.2 using OC4J 9.0.5.
    JDBC connections are provided via JNDI by specifying the datasource thru JDev. I've tried replacing the JDBC drivers that come with OC4J with the newer versions (that is, classes12.jar --> classes14.jar)
    Database version is 10.1.0.3.0
    I'm pretty much stuck until I can work this out, so any help would be appreciated.
    Thanks in advance,
    Eric Everman

    Hi LJ - Thanks for the reply.
    I'm leaving out detail about the framework I'm working within. For instance, the full method that saves the JGeometry back to the db is part of a Hibernate UserType for which I can't change the method signiture - thus the PreparedStatement.getConnection(). The full method looks like this:
    =========== Java Method =================
    public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    STRUCT struct = null;
    if (value != null) {
    if (value instanceof JGeometry) {
    JGeometry jg = (JGeometry)value;
    System.out.println("Storing a Geom object to the db. Info:");
    System.out.println(" Type: " + jg.getType());
    System.out.println(" # of points: " + jg.getNumPoints());
    System.out.println(" isPoint: " + jg.isPoint());
    System.out.println(" X, Y: " + jg.getFirstPoint()[0] + ", " + jg.getFirstPoint()[1]);
    //System.out.println(" elemInfo length: " + jg.getElemInfo().length); (throws error)
    OracleConnection oc = (OracleConnection) st.getConnection();
    struct = JGeometry.store(jg,oc);
    } else {
    throw new HibernateException("Cannot set GeometryType value to " + value.getClass().getName());
    } //keep null value
    st.setObject(index, struct);
    ==================================
    ==== Typical Output ==============
    05/01/04 20:53:08 Storing a Geom object to the db. Info:
    05/01/04 20:53:08 Type: 1
    05/01/04 20:53:08 # of points: 1
    05/01/04 20:53:08 isPoint: true
    05/01/04 20:53:08 X, Y: 385343.3057, 562597.748
    ==================================
    I've no reason to think that the connection I'd get from the prepared statement would be anything other then the connection returned from JNDI, but I'll try a simplified test to make sure.
    My Geom is point data - would I expect JGeometry.getElemInfo() to return null in that case? Currently it does return null immediately after I load the JGeom from the database.

  • JGeometry.createPoint help

    I am trying to insert a point into an Oracle 9i instance. I used the following code but get a ClassCastException when executing the store method.
    geoPoint.getAsOrdinateArray() returns a 2 element double[] representing a lat/lon pair.
    conn is of type java.sql.Connection
    geometry = JGeometry.createPoint (geoPoint.getAsOrdinateArray(), JGeometry.GTYPE_POINT, 8192);
    STRUCT shape = JGeometry.store(geometry, conn);
    Thanks for your help

    [12/15/04 9:18:41:197 PST] a9bed30 ExceptionUtil X CNTR0020E: Non-application exception occurred while processing method updateOracleCustomerGeoData on bean BeanId(CONWAY_OPERATIONS_EAR#CONWAY_CITY_OPERATIONS_EJB.jar#ScoAreaOpsEJB, null): java.lang.ClassCastException: com.ibm.ejs.cm.proxy.OracleConnectionProxy
         at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:128)
         at oracle.spatial.geometry.JGeometry.createDBDescriptors(JGeometry.java:1321)
         at oracle.spatial.geometry.JGeometry.store(JGeometry.java:1257)
         at com.con_way.sco.persist.AreaDataBean.addOracleCustomerGeoData(AreaDataBean.java:961)
         at com.con_way.sco.persist.AreaDataBean.updateOracleCustomerGeoData(AreaDataBean.java:872)
         at com.con_way.sco.AreaManagement.updateOracleCustomerGeoData(AreaManagement.java:91)
         at com.con_way.sco.area.ejb.AreaOpsBean.updateOracleCustomerGeoData(AreaOpsBean.java:172)
         at com.con_way.sco.area.ejb.EJSRemoteStatelessAreaOps_810c264a.updateOracleCustomerGeoData(EJSRemoteStatelessAreaOps_810c264a.java:420)
         at com.con_way.sco.area.ejb._AreaOps_Stub.updateOracleCustomerGeoData(_AreaOps_Stub.java:800)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.ibm.etools.utc.model.ReflectionMethodModel.invoke(ReflectionMethodModel.java:68)
         at com.ibm.etools.utc.servlet.InvokeServlet.invoke(InvokeServlet.java:110)
         at com.ibm.etools.utc.servlet.InvokeServlet.doPost(InvokeServlet.java:352)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
         at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
         at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
         at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
         at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
         at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
         at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
         at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:721)
         at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:374)
         at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:118)
         at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:134)
         at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:239)
         at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
         at com.ibm.servlet.engine.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:106)
         at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:154)
         at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:317)
         at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
         at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:477)
         at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:341)
         at com.ibm.ws.util.CachedThread.run(ThreadPool.java:144)

  • JDBC insert empty STRUCT (JGeometry) into SDO_GEOMETRY

    Hi!
    I need to insert empty or null value intro oracle table with SDO_GEOMETRY field.
    I'm using prepared statement.
    I have tried pstmt.setNull(1, null), pstmt.setObject(1, null)
    Normaly I do it like this:
    STRUCT obj = JGeometry.store(jgeom, conn);
    pstmt.setObject(1, obj);
    So I probably need to create an empty STRUCT or something.
    I have also tried using :
    StructDescriptor type_descriptor = StructDescriptor.createDescriptor ("MDSYS.SDO_GEOMETRY", conn); but I don't know if I'm using it right.
    The syntax is like:
    StructDescriptor structdesc = StructDescriptor.createDescriptor (sql_type_name, connection); but I don't know what sql_type_name means? Is it tablename, fieldname? Tried them all...no success.
    I've read that JDBC doesn't support that kind of insert with setNull, is there a workaround or any other way of doing this.
    Thanks in advance and have a nice day.
    Simon

    http://www.oracle.com/technology/tech/java/sqlj_jdbc/pdf/a96654.pdf seems to have the clues that you are looking for.
    BTW, we are adding a Connection.createStruct/Array method so that you can create these types of objects in portable with JDBC in JDBC 4

  • JGeometry and SDO_BUFFER of geodetic coordinates

    I can successfully execute SQL that will create a "circle" around a geodetic lat/long using the SDO_BUFFER. The goal is to persist the resulting "circle" that SDO_BUFFER calculates. However, even using JGeometry, I still get the error "Too Many Values" when inserting over JDBC.
    How can I execute the following SQL via JDBC? I'm using the JGeometry to "wrap" the point; however, I don't see how to use SDO_BUFFER.
    The following is the prepared statement:
    insert into t1 (?, ?, SDO_GEOM.SDO_BUFFER(?), ?, ?, ?, ?, ?)
    // create a JGeometry for the point reprenting the lat/long
    JGeometry landmarkGeo = JGeometry.createPoint(new double[]{latLong.getLongitude(), latLong.getLatitude()}, JGeometry.GTYPE_POINT, 8307);
    STRUCT struct = JGeometry.store(landmarkGeo, conn);
    stmt.setObject(3, struct);

    Your call to sdo_buffer is not correct (syntax error), so it ends up
    sending too many values to the table.
    > insert into t1 (?, ?, SDO_GEOM.SDO_BUFFER(?), ?, ?, ?, ?, ?)
    This closing ")" for sdo_buffer is not in the right place.
    Depending on which signature you are using for buffer, move
    the ")" to the right place.
    How many columns are there in your table ?
    siva

  • How to use java to store Multipolygon

    I fell victim to the ORA-00939 problem of too many arguments when inserting a geometry object into the database, and found details on the forum to use java to insert it instead. The code located was:
    double[] coords = new double[10000];
    for(int i=0; i<coords.length; i++)
    coords[i] = ....;
    JGeometry mypoly = JGeometry.createLinearPolygon(coords, 2/*dimensions*/, 8256);
    PreparedStatement ps = connection.prepareStatement("insert into states values(?)");
    //convert JGeometry instance to DB STRUCT
    STRUCT obj = JGeometry.store(mypoly, connection);
    ps.setObject(1, obj);
    ps.execute();
    The SDO_GEOMETRY I want to insert is of SDO_GTYPE 2007 (collection of polygons) [in the example below, 2]
    I can see in the sample code where to put the SRID (8307), but nowhere in the code, and nowhere in the Geometry class where I can create a multipolygon.
    Anyone care to help with this?
    As a secondary question: Some of the sites I'm updating have a boundary delineated by one polygon, some by more than one - can SDO_GTYPE 2007 be used for all, regardless of how many there are?
    UPDATE LOC SET SITE_BOUNDARY=MDSYS.SDO_GEOMETRY(
    2007,
    8307,
    SDO_POINT_TYPE(60.49772542, -1.452049075, NULL),
    MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1, 105,1003,1),
    MDSYS.SDO_ORDINATE_ARRAY(50.49678550013553,-7.217321117344117, ... <trimmed, you don't want to see it all>...)
    WHERE SITECODE='970A3';

    This didn't work for me, but it got me close. I kept getting a null pointer exception on JGeometry.closeCoord when I used Object[]. Didn't matter if I made sure to close my rings or not. (The API docs suggest it will do this for you.)
    Nonethelss, the following example does work:
    double[] poly1 = {50,100, 51,101, 52,102, 53,103, 54,104};
    double[] poly2 = {60,110, 61,111, 62,112, 63,113};
    double[][] jpoly = {poly1, poly2};
    JGeometry jgeom = JGeometry.createLinearPolygon(jpoly, 2, 8307);
    The first array of doubles contains the x,y points seqentially. {x1,y1, x2,y2, x3,y3, ...}
    Then you just have an array of the array of doubles. One for each polygon in the multipolygon.
    Then, as luc said above, make sure you set the type correctly for multi or single polygon.
    jgeom.setType( JGeometry.GTYPE_MULTIPOLYGON );
    -or-
    jgeom.setType( JGeometry.GTYPE_POLYGON );
    I tested this using the sdoapi.jar from my Oracle 11.2.0.1 install, so I'm pretty sure I'm up to date.
    Hope that helps somebody else.
    -C.

  • JSP Compiler and ClassCastException

     

    Have been using JDK1.2.2 from sun since day one and I've been seeing
              ClassCastException since day 1 too.
              Don't think it had anything to do with the compiler.
              "Jun Ying" <[email protected]> wrote in message
              news:[email protected]...
              > I noticed something that might be causing the ClassCastException and has
              not
              > been mentioned: the compiler that is used for jspc. I remember seeing a
              few
              > people mentioning extra classes in the workDir (ie, the bean class that is
              > being used). This is caused by using a smart compiler such as jikes or
              sj.
              > While those compilers will get you more speed for newly modified jsp's,
              they
              > resolve dependencies and recompile all the referenced classes. The result
              > is that the bean class gets recompiled and put into workDir. So no matter
              > where you put the workDir, you end up getting a new copy of the bean class
              > file, which is reloaded by the classloader that loads the newly compiled
              > JSP. That copy of the class file is considered "different" from the one
              > from the normal system classpath or the weblogic.class.path. Thus the
              > ClassCastException. So if you see java classes other than the jsp's in
              the
              > workDir, make sure you are using javac from the sun jdk. So to answer
              > Anish's question, WebLogic is not sticking a copy of the bean class.
              > Rather, it's the java compiler that you are using.
              >
              > Jun Ying
              > Meritsoft, Inc
              >
              >
              > "Michael Boudreau" <[email protected]> wrote in message
              > news:[email protected]...
              > > Hello,
              > >
              > > Well we ran into the same problem here at my company, and we have been
              > > pulling our hair out. I was reading through the jsp 1.1 spec, and
              > > thought I might try using the <jsp:useBean ...> tag instead of the <%@
              > > page import ...> tag. After careful inspection of the resulting .java
              > > file, I found that the <jsp:useBean ...> tag does not put insert any
              > > import statements, but simply declares the bean with the fully
              > > qualified package name. I am sure that this is not new news to anyone;
              > > however, the class cast exception went away (knock on wood, cross
              > > fingers, whatever).
              > >
              > > Basically, my statement looked like this:
              > > <jsp:useBean id="beanname" type="com.company.Class" scope="session" />
              > >
              > > My question is: is there something that I am missing or have not
              > > thought of? Because so far, this "seems" to be working, but I have
              > > been reading posts that say this does not work.
              > >
              > > Oh, one last quick note to BEA. While I was looking at the
              > > generated .java file from the jsp file, I found that weblogic's jspc is
              > > still generating getValue and setValue methods for HttpSession....
              > > which has been deprecated as of the servlet 2.2 spec.
              > >
              > > Michael
              > >
              > >
              > >
              > >
              > > Anish Parvataneni wrote:
              > >
              > > > Hi,
              > > >
              > > > I have a JSP which uses two different classes. Whenever, I change the
              > > > JSP and save it to recompile, there is a ClassCastException. ( I store
              > > > them in the session and load them) . Thats common ! The solution to
              this
              > > > as per documentation is to get rid of the classes in the workingDir of
              > > > JSP. However, I can find ONLY ONE of the classes in the workingDir. I
              > > > delete that class and the JSP works. I change the JSP , problem
              recurrs.
              > > >
              > > > 1. Why does weblogic stick a copy of the class in the workingDir,
              > > > everytime the JSP compiles, although it is available in the weblogic
              > > > classpath ?
              > > > 2. Why is it happening to only one of the classes I use in the JSP ?
              > > > 3. How can I make sure that this class is not available in the
              > > > workingDir, other than deleting it EVERYTIME.
              > > >
              > > > Thanks
              > > > Anish
              > >
              >
              >
              

  • Creating a point geometry with coordinate transformation using JDBC

    If I execute the following SQL statement using a tool such as TOAD then I get a correct value for the point in the oracle column.
    INSERT INTO node (id, position) VALUES (53, SDO_CS.TRANSFORM(SDO_GEOMETRY(2001, 26910, SDO_POINT_TYPE(489535.0, 5457841.0, NULL), NULL, NULL), 4269))
    Point geometry:
    (2001, 4269, (-123.143865452971, 49.2732377100255, ), , )
    If I execute the same statement using JDBC in a Statement or PreparedStatement the Point in the oracle column has 0,0 for the coordinates.
    Point: geometry
    (2001, 4269, (0, 0, ), , )
    In both cases the SQL is exactly the same.
    my JDBC code is
    String insertSql = "INSERT INTO node (id, position) VALUES (" + id
    + ", SDO_CS.TRANSFORM(SDO_GEOMETRY(2001, " + geometrySrid
    + ", SDO_POINT_TYPE(" + coordinate2d.x + ", " + coordinate2d.y
    + ", NULL), NULL, NULL), " + srid + "))";
    Statement insertStatement = connection.createStatement();
    try {
    insertStatement.execute(insertSql);
    } finally {
    JdbcUtils.closeStatement(insertStatement);
    connection.commit();
    Any ideas why this is happening?
    I've tried to do the coordinate transformation in a separate call and pass in the STRUCT returned from that, using JGeometry to create a STRUCT for the value, using a WKT geometry and none of these approaches seem to work

    Paul,
    I have seen this work using JGeometry and STRUCT objects with PreparedStatements. Here's some sample code that seems to work just fine:
    ResultSet rs = null;
    try {
    PreparedStatement ps =
    getConn().prepareStatement("select SDO_CS.TRANSFORM(?, ?) from dual");
    /* constucts JGeometry objects using simple points (doubles) and SRID
    * Per the Javadoc, JGeometry objects can be constructed using the same
    * notation and signature as SDO_GEOMETRY objects -
    * JGeometry(int gtype, int srid, double x, double y, double z, int[] elemInfo, double[] ordinates) */
    JGeometry j_geom1 = new JGeometry(-122.4, 37.8, 8265);
    int newSRID = 4269;
    //convert JGeometry instances to DB STRUCT
    STRUCT obj1 = JGeometry.store(j_geom1, getConn());
    ps.setObject(1, obj1);
    ps.setInt(2, newSRID);
    rs = ps.executeQuery();
    while (rs.next()) {
    //System.out.println(rs.getString(1));
    STRUCT st = (oracle.sql.STRUCT) rs.getObject(1);
    JGeometry j_geom = JGeometry.load(st);
    System.out.println(j_geom);
    ps.close();
    rs.close();
    conn.close();
    } catch (Exception e) {
    System.err.print(e);
    Hope this helps.
    -Justin

  • NullPointerException in Class oracle.jdbc.driver.PhysicalConnection

    Can anybody help me? We try to build a STRUCT by using the Class oracle.spatial.geometry.JGeometry for save this in a Oracle Database at runtime. Since we changed to Oracle IAS 10.1.2.0.2 we got the following error by doing that:
    java.lang.NullPointerException
         at oracle.jdbc.driver.PhysicalConnection.isDescriptorSharable(PhysicalConnection.java:5078)
         at oracle.sql.ARRAY.<init>(ARRAY.java:118)
         at oracle.spatial.geometry.JGeometry.store(JGeometry.java:1289)
         at de.jogwart.database.ORCL2GeometryHelpers.A(Unknown Source)
    Does anybody know this mistake? Does anybody know what the methode "isDescriptorSharable" do?

    Hi!
    I'm facing the same problem. Do you solve this issue?
    Best regards,
    Gerardo

  • Mapviewer update problem

    Hello,
    in my application I am creating polygons on the fly and storing them into table on which a MV theme is based. after that my polygons are not rendered correctly in my app nor in map builder - but if I restart map builder or application they are ok - so what additional task to do after storing polygons into table - some theme reloading or what?
    thanks,
    Branislav

    Hi Joao,
    I am usind JDBC:
    1. delete table:
    public void prepare() {
              try {
                   PreparedStatement ps1 = conn.prepareStatement("DELETE polygons");
                   ps1.execute();
                   ps1.close();
              } catch (SQLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    2. insert into table:
    private void storePolys(List polys) {
              try {
                   boolean isAutoCommit = conn.getAutoCommit();
                   conn.setAutoCommit(false);
                   PreparedStatement ps = conn
                             .prepareStatement("INSERT INTO polygons (geometry, cena2) values (?,?)");
                   for (Iterator iter = polys.iterator(); iter.hasNext();) {
                        Map map = (Map) iter.next();
                        List poly = (List) map.get("poly");
                        Number price = (Number) map.get("price");
                        JGeometry j_geom = JGeometry.createLinearPolygon(
                                  polyAsDoubleArray(poly), 2, 2065);
                        STRUCT polygon = JGeometry.store(j_geom, conn);
                        ps.setObject(1, polygon);
                        ps.setBigDecimal(2, (BigDecimal) price);
                        ps.execute();
                   ps.close();
                   conn.commit();
                   conn.setAutoCommit(isAutoCommit);
              } catch (SQLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    and how it behaves you can see in this flash demo:
    http://www.freewebalbum.com/demo2/Untitled2/Untitled2.html
    thanks,
    Branislav

  • ShapefileReaderJGeom LRS

    Hi.
    Does anyonr have sample code for converting ESRI shape files with PolylineM features to SDO using ShapefileReaderJGeom Class? I have Oracle 10g r2 and the latest sdoapi library. It always fails during getGeometry / getGeometryBytes method. Perhaps I'm not passing the correct arguments but the javadoc is very vague and is lacking samples.
    Thansks!
    BC
    Here's the code I used as my basis:
    import oracle.spatial.util.*;
    import java.sql.*;
    import oracle.sql.STRUCT;
    import oracle.jdbc.driver.*;
    import oracle.spatial.geometry.JGeometry;
    public class Shape2JGeom2
    //Standard constructor
    public Shape2JGeom2()
    public static void main(String[] args)
    Shape2JGeom2 shape2JGeom = new Shape2JGeom2();
    //ESRI shapefile (.dbf, .shx and .shp files)
    String shapefile = "d:/code/spatial/states";
    int shpRecords;
    int dim = 2;
    String url = "jdbc:oracle:thin:@truth.oraclecorp.com:1521:orcl";
    String username = "scott";
    String password = "tiger";
    Connection conn = null;
    try
    DriverManager.registerDriver(new OracleDriver());
    conn = DriverManager.getConnection(url, username, password);
    catch (Exception e)
    e.printStackTrace();
    try
    //New ESRI shapefile reader which includes methods for object extraction and description
    ShapefileReaderJGeom sfr = new ShapefileReaderJGeom(shapefile,dim);
    shpRecords = sfr.numRecords();
    System.out.println("The number of records in this ESRI shapefile is: " + shpRecords);
    PreparedStatement ps = conn.prepareStatement("insert into states_test (id,geom) values(?,?)");
    for (int i = 0;i<shpRecords;i++)
    //Extract bytes out of ESRI shapefile and create an Oracle JGeometry object
    JGeometry jgeom = sfr.getGeometry(sfr.getGeometryBytes(i,dim),dim,0);
    //Convert JGeometry instance to DB STRUCT
    STRUCT obj = JGeometry.store(jgeom, conn);
    //Insert id and JGeometry (as SDO_GEOMETRY) into Oracle DB table
    ps.setInt(1,i);
    ps.setObject(2, obj);
    ps.execute();
    System.out.println("Record " + i + " inserted into the database");
    ps.close();
    conn.close();
    catch (Exception e)
    e.printStackTrace();
    }

    Dan,
    I was never able to get the java-based shapefile converter to work with polylineM features. The following thread details the error message returned: Java SDOAPI error
    Thanks.
    BC

  • Layer Dimensionality does not match geometry dimensions

    I am using a Oracle 9i instance and am try to insert a geometry using the following code but am getting an exception. Any help would be much appreciated.
                   conn = getConnection(Connection.TRANSACTION_SERIALIZABLE);
                   OracleConnection oracleConnection = unwrapOracleConnection(conn);
                   GeoPoint[] points = area.getPoints();
                   double[] ordinates = new double[points.length*2];
                   for (int i = 0, n = points.length; i < n; i++){
                        ordinates[( i * ( LONGITUDE_INDEX + 1 ) ) + i ] = points.getLongitude();
                        ordinates[( i + LATITUDE_INDEX + ( i * 1 ) ) ] = points[i].getLatitude();
                   geometry = JGeometry.createLinearPolygon(ordinates,JGeometry.GTYPE_MULTIPOLYGON,8192);
                   STRUCT struct = JGeometry.store(geometry,oracleConnection);
                   statement = oracleConnection.prepareStatement(query);
                   statement.setBigDecimal(AREA_INDEX,area.getAreaId());
                   statement.setString(NAME_INDEX,area.getAreaName());
                   statement.setString(SIC_INDEX,area.getSic());
                   statement.setObject(SHAPE_INDEX,struct);
                   statement.setString(DESCRIPTION_INDEX,area.getDescription());
                   statement.execute();
    ORA-29875: failed in the execution of the ODCIINDEXINSERT routine ORA-13364: Layer Dimensionality does not match geometry dimensions ORA-06512: at "MDSYS.SDO_INDEX_METHOD_9I", line 319 ORA-06512: at line 1
    java.sql.SQLException: ORA-29875: failed in the execution of the ODCIINDEXINSERT routine
    ORA-13364: Layer Dimensionality does not match geometry dimensions
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD_9I", line 319
    ORA-06512: at line 1

    If I change the following line of code:
    geometry = JGeometry.createLinearPolygon(ordinates,JGeometry.GTYPE_MULTIPOLYGON,8192);
    To:
    geometry = JGeometry.createLinearPolygon(new Object[]{ordinates},JGeometry.GTYPE_MULTIPOLYGON,8192);
    I get the following exception:
    RemoteException occurred in server thread; nested exception is: com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ArrayIndexOutOfBoundsException: -7
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
         com.ibm.ejs.container.UncheckedException: ; nested exception is:
         java.lang.ArrayIndexOutOfBoundsException: -7
    com.ibm.ejs.container.UncheckedException: ; nested exception is:
         java.lang.ArrayIndexOutOfBoundsException: -7
    java.lang.ArrayIndexOutOfBoundsException: -7

  • Multi-threaded java application and deadlock down in Oracle library

    Hello,
    I was running our Java (JDK 1.6_14) application from Windows XP hitting an Oracle (10g) instance on Linux and came across a deadlock issue with two (of 10) threads. Below is the stacktraces (based on Java thread-dump at the command line). This code I've run 30-40 times with no problems of deadlocks.
    The Oracle library that we're using for our Java application is ojdbc14.jar and sdoapi.jar (for spatial).
    We create our Connection as follows (for each thread -- 10 of them):
    public class Worker implements Runnable
    private Connection _Conn;
    public Worker(...)
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    _Conn = DriverManager.getConnection(url, username, password);
    _Conn.setAutoCommit(false);
    The code that is already executing these same lines below was already executed by other threads (in their own instance of Worker). So this is very confusing.
    Any ideas? Version of the .jar files? Place how we're calling "DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());"?
    Thanks, Jim
    Found one Java-level deadlock:
    =============================
    "WORKER_1":
    waiting to lock monitor 0x02b50d8c (object 0x22e8af80, a oracle.jdbc.driver.T4CConnection),
    which is held by "WORKER_0"
    "WORKER_0":
    waiting to lock monitor 0x02b50d24 (object 0x22f6d258, a oracle.sql.StructDescriptor),
    which is held by "WORKER_1"
    Java stack information for the threads listed above:
    ===================================================
    "WORKER_1":
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3410)
    - waiting to lock <0x22e8af80> (a oracle.jdbc.driver.T4CConnection)
    at oracle.sql.StructDescriptor.initMetaData1_9_0(StructDescriptor.java:1516)
    - locked <0x22f6d258> (a oracle.sql.StructDescriptor)
    - locked <0x22eabd80> (a oracle.jdbc.driver.T4CConnection)
    at oracle.sql.StructDescriptor.initMetaData1(StructDescriptor.java:1408)
    at oracle.sql.StructDescriptor.isInstantiable(StructDescriptor.java:892)
    at oracle.sql.STRUCT.<init>(STRUCT.java:148)
    at oracle.spatial.geometry.JGeometry.store(JGeometry.java:2954)
    at oracle.spatial.geometry.JGeometry.store(JGeometry.java:3777)
    .......... <our package/class>
    "WORKER_0":
    at oracle.sql.StructDescriptor.initMetaData1_9_0(StructDescriptor.java:1494)
    - waiting to lock <0x22f6d258> (a oracle.sql.StructDescriptor)
    - locked <0x22e8af80> (a oracle.jdbc.driver.T4CConnection)
    at oracle.sql.StructDescriptor.initMetaData1(StructDescriptor.java:1408)
    at oracle.sql.StructDescriptor.isInstantiable(StructDescriptor.java:892)
    at oracle.sql.STRUCT.<init>(STRUCT.java:148)
    at oracle.spatial.geometry.JGeometry.store(JGeometry.java:2954)
    at oracle.spatial.geometry.JGeometry.store(JGeometry.java:3777)
    ..........<our package/class>
    Edited by: Jim Atharris on Aug 24, 2009 6:23 PM

    Thanks Toon for your reply.
    Yes each Worker (executing in their own thread) has their own instance of Connection as per the Constructor (shown in original post). That is why this is weird.
    I'll check the v$session when I get into work.
    Based on our code that I put in the original email, Connection is a non-static variable. We have a per Thread per instance of Worker of which that Worker instance has its own instance of Connection. So I'm wonder if the following needs to occur:
    Both of these lines (from original email) need to happen in the main thread as follows:
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    for (i=0;i<NUM_OF_WORKERS)
    _Conn = DriverManager.getConnection(url, username, password);
    new Worker(_Conn);
    Thanks,Jim

  • About sdoapi

    Hello,
    I have some sample codes using oracle spatial java library. They are:
    import oracle.sdoapi.geom.CoordPoint;
    import oracle.sdoapi.geom.CurveString;
    import oracle.sdoapi.geom.Geometry;
    import oracle.sdoapi.geom.LineString;
    I have downloaded the library of the version 10g from OTN. But it does not match the sample codes. In 10g there is only the package oracle.spatial.geometry in sdoapi.jar.
    Does any one have idea about it? Shall I install an Oracl spatial Java Library of the old version?
    Thanks in advance.

    You only need the oracle.spatial.geometry package.
    oracle.spatial.util contains utility functions. E.g. to convert between JGeometry and Well-Known Text or Binary.
    Did the samples come with the new sdoapi download?
    If they did it's a mistake.
    They seem to be samples for the older jar.
    The javadoc that comes along with the sdoapi download has a simple example:
    The main methods for reading/writing db geometries are: load(STRUCT) and store(). Here is a simple example showing how to use these two methods:
    /// reading a geometry from database
    ResultSet rs = statement.executeQuery("SELECT geometry FROM states where name='Florida'");
    STRUCT st = (oracle.sql.STRUCT) rs.getObject(1);
    //convert STRUCT into geometry
    JGeometry j_geom = JGeometry.load(st);
    // ... manipulate the geometry or create a new JGeometry ...
    /// writing a geometry back to database
    PreparedStatement ps = connection.prepareStatement("UPDATE states set geometry=? where name='Florida'");
    //convert JGeometry instance to DB STRUCT
    STRUCT obj = JGeometry.store(j_geom, connection);
    ps.setObject(1, obj);
    ps.execute();

Maybe you are looking for

  • Issue with reading a xml file from xsl

    Hi, When I am trying to read a xml file from xsl, I am getting unwanted output. Following is the XSL: <?xml version="1.0" encoding="UTF-8" ?> <?oracle-xsl-mapper   <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->   <mapSources>     <

  • Connecting MacBook to printer via wireless network

    I have a wireless network via cable modem with some PCs attached and a printer but am having trouble connecting my new MacBook to the HP LaserJet 2100 printer via wireless. I do not have airport express and not sure I need it to have the MacBook prin

  • Short dump in OLE_FLUSH_CALL

    Hi all, I am getting a runtime error in 'OLE_FLUSH_CALL'  DESTINATION SAPGUI. The exception is "CALL_METHOD_FAILED" from above FM. Strangely the error comes only in production. I have checked & compared the quality & production systems the settings a

  • Lock objects to allow 1 user to insert data at a time

    Is it possible to Use lock objects to allow only 1 user to insert data into a  database table at a time. I am creating Assets using "BAPI_FIXEDASSET_CREATE1". To create "n" assets similar to the asset I use a DO loop in my program and call the BAPI.

  • PO value differnt from Invoice Value

    Hi, Help me in following senario I have PO for a QTY of 100 with $2 as unit price. Therefore the PO value is $200. I do a total Goods receive for the 100 QTY against the PO. Now my 100 goods are lying at my stores, ready for production. Sometimes lat