Example 1: Retrieving a Point From a Table

The commented code fragment below shows how to retrieve a Point shape from a database table using a SELECT statement.

The points_t table was created using the following SQL statement:
CREATE TABLE points_t (id integer, pt st_point);
The database connection URL is passed as an argument to the example.
void example(String url) {
// load the Informix JDBC driver
Class.forName("com.informix.jdbc.IfxDriver");
// get the connection
Connection conn = DriverManager.getConnection(url);
// get the custom type map associated with the spatial data types
Map typeMap = IfxSQLData.enableTypes(conn);
// set the CoordRefManager connection
CoordRefManager.getInstance().setConnection(conn);
// run a query and fetch the spatial data
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT id, pt FROM points_t");
while (rs.next()) {
Integer id = (Integer) rs.getObject(1);
IfxPoint pt = (IfxPoint) rs.getObject(2, typeMap);
// print out x and y coordinates
System.out.println("X=" + pt.getX() + " Y=" + pt.getY());
}
}

Copyright© 2019 HCL Technologies Limited