Client 2—Adding Error Checking
In the previous section, I mentioned that the DriverManager.getConnection() method will throw an exception whenever it fails. Listing 13.3 shows the second JDBC client. This version is nearly identical to client1.java, except that client1, ignored any exceptions and in client2, you will intercept them and produce friendlier error messages.
Listing 13.3. client2.java
1 // 2 // File: client2.java 3 // 4 5 import java.sql.*; 6 7 public class client2 8 { 9 public static void main( String args[] ) 10 { 11 String driver = "org.postgresql.Driver"; 12 String url = "jdbc:postgresql:movies"; 13 String user = "korry"; 14 String pwd = "cows"; 15 16 try 17 { 18 Class.forName( driver ); 19 } 20 catch( ClassNotFoundException ... |
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.