Querying and Displaying Geometries

The following code fragment demonstrates how to query geometries and display geometry data.

Connection conn;
Map typeMap;
// Acquire a database connection
...
// Set up the typemap
typeMap = IfxSQLData.enableTypes(conn);
// Set the CoordRefManager connection
CoordRefManager.getInstance().setConnection(conn);
// Running the query
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT id, geom FROM geomtab where id >= 0");
while (rs.next()) {
Integer id = (Integer)rs.getObject(1);
Geometry geo = (Geometry) rs.getObject(2, typeMap);
if (geo == null) {
System.out.println("NULL");
continue;
}
// Print out the well-known text representation
System.out.println(geo.asText());
}
stmt.close();

Copyright© 2019 HCL Technologies Limited