Permalink
Browse files

docs: fix spelling and chapter, update sample code (#1098)

metioned -> mentioned
Chapter 12 -> Chapter 13
change sample code to match PgJDBC code style guidelines
explicitly close (via try-with-resources) the Statement and ResultSet in retrieveCircle(Connection)
  • Loading branch information...
bpd0018 authored and davecramer committed Feb 2, 2018
1 parent df4e7fa commit 0cfffa841b9b8d2040fe6c576aa77edfd399bbc0
Showing with 37 additions and 43 deletions.
  1. +37 −43 docs/documentation/head/geometric.md
@@ -1,9 +1,9 @@
---
layout: default_docs
title: Geometric Data Types
header: Chapter 9. PostgreSQL™ Extensions to the JDBC API
header: Chapter 9. PostgreSQL™ Extensions to the JDBC API
resource: media
previoustitle: Chapter 9. PostgreSQL™ Extensions to the JDBC API
previoustitle: Chapter 9. PostgreSQL™ Extensions to the JDBC API
previous: ext.html
nexttitle: Large Objects
next: largeobjects.html
@@ -12,10 +12,11 @@ next: largeobjects.html
PostgreSQL™ has a set of data types that can store geometric features into a
table. These include single points, lines, and polygons. We support these types
in Java with the org.postgresql.geometric package. Please consult the Javadoc
for the details of available classes and features metioned in [Chapter 12, *Further Reading*](reading.html).
mentioned in [Chapter 13, *Further Reading*](reading.html) for details of
available classes and features.
<a name="geometric-circle-example"></a>
**Example 9.1. Using the CIRCLE datatype JDBC**
**Example 9.1. Using the CIRCLE datatype JDBC**
```java
import java.sql.*;
@@ -24,47 +25,40 @@ import org.postgresql.geometric.PGpoint;
import org.postgresql.geometric.PGcircle;
public class GeometricTest {
public static void main(String args[]) throws Exception {
String url = "jdbc:postgresql://localhost:5432/test";
try (Connection conn = DriverManager.getConnection(url, "test", "")) {
try (Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TEMP TABLE geomtest(mycirc circle)");
}
insertCircle(conn);
retrieveCircle(conn);
}
}
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/test";
private static void insertCircle(Connection conn) throws SQLException {
PGpoint center = new PGpoint(1, 2.5);
double radius = 4;
PGcircle circle = new PGcircle(center, radius);
try (PreparedStatement ps = conn.prepareStatement("INSERT INTO geomtest(mycirc) VALUES (?)")) {
ps.setObject(1, circle);
ps.executeUpdate();
}
}
Connection conn = DriverManager.getConnection(url,"test","");
private static void retrieveCircle(Connection conn) throws SQLException {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT mycirc, area(mycirc) FROM geomtest")) {
while (rs.next()) {
PGcircle circle = (PGcircle)rs.getObject(1);
double area = rs.getDouble(2);
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMP TABLE geomtest(mycirc circle)");
stmt.close();
insertCircle(conn);
retrieveCircle(conn);
conn.close();
}
private static void insertCircle(Connection conn) throws SQLException {
PGpoint center = new PGpoint(1, 2.5);
double radius = 4;
PGcircle circle = new PGcircle(center, radius);
PreparedStatement ps = conn.prepareStatement("INSERT INTO geomtest(mycirc) VALUES (?)");
ps.setObject(1, circle);
ps.executeUpdate();
ps.close();
}
private static void retrieveCircle(Connection conn) throws SQLException {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT mycirc, area(mycirc) FROM geomtest");
rs.next();
PGcircle circle = (PGcircle)rs.getObject(1);
double area = rs.getDouble(2);
PGpoint center = circle.center;
double radius = circle.radius;
System.out.println("Center (X, Y) = (" + center.x + ", " + center.y + ")");
System.out.println("Radius = " + radius);
System.out.println("Area = " + area);
}
System.out.println("Center (X, Y) = (" + circle.center.x + ", " + circle.center.y + ")");
System.out.println("Radius = " + circle.radius);
System.out.println("Area = " + area);
}
}
}
}
}
```

0 comments on commit 0cfffa8

Please sign in to comment.