postgresql-jdbc.git / summary / log / commit / refs
commit 0cfffa841b9b8d2040fe6c576aa77edfd399bbc0
Author: bpd0018 <bpd0018@gmail.com>
Commit: Dave Cramer <davecramer@gmail.com>
Date: Fri Feb 02 20:11:38 2018 +0000
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)
docs/documentation/head/geometric.md | 80 +++++++++++++++++-------------------
1 file changed, 37 insertions(+), 43 deletions(-)
diff --git a/docs/documentation/head/geometric.md b/docs/documentation/head/geometric.md
index 0d37dbbf..f6a6dc64 100644
--- a/docs/documentation/head/geometric.md
+++ b/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);
+ }
+ }
+ }
+ }
}
```
[parent: df4e7fa07c20]