[postgis-users] how to get point, polygon value in postgis JDBC?

LeeHyung Joo - Kevin procarrie at hotmail.com
Thu Nov 3 22:33:02 PDT 2011


Hi all.

I have a big problem on my work.

First of all, the version based on my work is PostgreSQL : 8.1.11, PostGIS : 1.5.2.

The problem is I can not get the value of Point and Polygon.

The code is below :

blah blah --------------------------------------------------------------------------------
public Test find(String Id) throws DAOException, ClassNotFoundException, SQLException {
        Class.forName("org.postgresql.Driver");
        String url = "jdbc:postgresql://localhost:8080/testdao";
        Connection conn = DriverManager.getConnection(url, admin, apple);
        PreparedStatement ps = conn.prepareStatement("select name, addr, ST_AsText(position) from listFriend where id=?");
        ps.setString(1, Id);

        ResultSet rs = ps.executeQuery();
        
//        ((org.postgresql.PGConnection)conn).addDataType("point",Class.forName("org.postgis.Point"));
        
        while(rs.next()) {
            test = new Test();
            p = new Point();
            
            test.setName(rs.getString(1));
            test.setAddr(rs.getString(2));
            test.setPosition(p);
//            System.out.println(rs.getString(3));
------------------------------------------------------------------------------------------

If I run the sentence, "System.out.println(rs.getString(3));, it works. It prints right output like "Point(13.123 11.123)".

But I don't know how to fix test.setPosition(p);

any helps will be thank.


P.S. is it possible to be reason why the low or high version of PostgreSQL and PostGIS?


Best Regards
Kevin Lee.
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20111104/4a1cc65e/attachment.html>


More information about the postgis-users mailing list