[postgis] ClassCastException with PostGis Example

Silvio torodedutoesdraiato at yahoo.it
Wed Jan 9 04:36:42 PST 2002


Yes, all is ok!
If I try to retrieve the geometry column as a String and print it the
example works.
But, what does strange situation means?
The database where the program gets the data has three objects. I have
inserted this object with geometryFromText function.
Now, this function should record a geometry object on the database but
instead it records a String object!!!?

Is this a bug? I don't think this but can somebody say me where is the
error?


Buffa S.

----- Original Message -----
From: "Paul Ramsey" <pramsey at refractions.net>
To: <postgis at yahoogroups.com>
Sent: Tuesday, January 08, 2002 8:27 PM
Subject: Re: [postgis] ClassCastException with PostGis Example


> Some tests might help see where things are breaking:
> - Print out obj.toString() before casting it.
> - Retrieve the geometry column as a String and print that out too.
>
> Silvio wrote:
> >
> > Hi,
> >
> > I have just installed PostGis with PostGreSql but the PostGis Example
> > doesn't work.
> >
> > This is the example (http://postgis.refractions.net/docs/x441.html)
> >
> > import java.sql.*;
> >   import java.util.*;
> >   import java.lang.*;
> >   import org.postgis.*;
> >
> >   public class JavaGIS {
> >     public static void main(String[] args)
> >     {
> >       java.sql.Connection conn;
> >       try
> >       {
> >         /*
> >         * Load the JDBC driver and establish a connection.
> >         */
> >         Class.forName("org.postgresql.Driver");
> >         String url = "jdbc:postgresql://localhost:5432/database";
> >         conn = DriverManager.getConnection(url, "postgres", "");
> >
> >         /*
> >         * Add the geometry types to the connection. Note that you
> >         * must cast the connection to the pgsql-specific connection *
> > implementation before calling the addDataType() method.
> >         */
> >
> >
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeom
> > etry");
> >
> >
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d")
> > ;
> >
> >                   /*
> >         * Create a statement and execute a select query.
> >         */
> >         Statement s = conn.createStatement();
> >         ResultSet r = s.executeQuery("select AsText(geom) as geom,id
from
> > geomtable");
> >         while( r.next() )
> >         {
> >           /*
> >           * Retrieve the geometry as an object then cast it to the
geometry
> > type.
> >           * Print things out.
> >           */
> >
> >           PGgeometry geom = (PGgeometry)r.getObject(1);
> > ********************CAST ERROR*****************
> >
> >           int id = r.getInt(2);
> >                       System.out.println("Row " + id + ":");
> >           System.out.println(geom.toString());
> >         }
> >                   s.close();
> >         conn.close();
> >       }
> >       catch( Exception e )
> >       {
> >         e.printStackTrace();
> >       }
> >     }
> >   }
> >
> > The compiling phase is ok
> > After, when I try to run the class I get the following error:
> >
> > java.lang.ClassCastException: java.lang.String
> >         at PostGis.main(PostGis.java:42)
> >
> > (the error is referred to the line 42 where I have written "CAST ERROR")
> >
> > I hope that somebody can help me!!
> >
> > Thanks in advance.
> >
> > Silvio B.
> >
> >
> > To unsubscribe from this group, send an email to:
> > postgis-unsubscribe at yahoogroups.com
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
> --
>       __
>      /
>      | Paul Ramsey
>      | Refractions Research
>      | Email: pramsey at refractions.net
>      | Phone: (250) 885-0632
>      \_
>
>
> To unsubscribe from this group, send an email to:
> postgis-unsubscribe at yahoogroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Tiny Wireless Camera under $80!
Order Now! FREE VCR Commander!
Click Here - Only 1 Day Left!
http://us.click.yahoo.com/WoOlbB/7.PDAA/ySSFAA/PhFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
postgis-unsubscribe at yahoogroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 





More information about the postgis-users mailing list