Client 3—Processing Queries

The next client executes a hard-coded query, intercepts any errors, and prints the result set. I've factored most of the code into separate methods to make it easier to follow. Listing 13.5 shows client3.java.

Listing 13.5. client3.java (Part 1)
 1 //
 2 //  File: client3.java
 3 //
 4
 5 import java.sql.*;
 6
 7 public class client3
 8 {
 9   public static void main( String args[] )
10   {
11     Class driverClass = loadDriver( "org.postgresql.Driver" );  12 13 if( driverClass == null ) 14 return; 15 16 if( args.length != 1 ) 17 { 18 System.err.println( "usage: java client3 <url>" ); 19 return; 20 } 21 22 Connection con = connectURL( args[0] ); 23 24 if( con != null ) 25 { 26 ResultSet result = execQuery( con, "SELECT * FROM tapes;" ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.