[postgis-users] Postgis problem : Can not compile the code successful

John john123apple at 163.com
Mon Oct 20 23:44:16 PDT 2008


 
 
   My name is john, this day i have some problem about Postgis,
 
   I have readed Postgis Documentation, and try to compile source code.
   
   I am using Postgresql 8.2.10 version,and using the computer language's java.
 
   I use the JDK 1.5 and Tomcat 6.0.
  
   In postgis-1.3.3.pdf source code is:
  4.8 Java Clients (JDBC)

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.PGgeometry"); 
((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);
int id = r.getInt(2);
System.out.println("Row " + id + ":");
System.out.println(geom.toString());
}
s.close();
conn.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
 
I can not compile this code successful, always report wrong .
 
can you help me, send the right code to my email.
 
                             Thanks
 
                                     john
    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20081021/87e82f30/attachment.html>


More information about the postgis-users mailing list