HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Rebel Without a Clause"
Vol. 8, Issue 3, p. 48

	



Listing 1

 1: OutputStreamWriter out = ...
 2: java.sql.Connection conn = ...
 3: try {
 4:   Statement stat = conn.createStatement();
 5:   ResultSet rs = stat.executeQuery(
 6:             "select uid, name from user");
 7:   while (rs.next())
 8:   {
 9:    out.println("User ID : " + rs.getString("uid") +
10:         ", name : " + rs.getString("name"));
11:   }
12: }
13: catch(SQLException sqlex)
14: {
15:   out.println("Warning : data incomplete due to exception");
16:   throw new ApplicationException(
17:             "SQL error while reading", sqlex);
18: }
19: catch(IOException ioex)
20: {
21:   throw new ApplicationException(
22:             "I/O error while writing", ioex);
23: }
24:finally 
25:{
26:  if (conn != null) {
27:  try {
28:      conn.close();
29:  }
30:  catch(SQLException sqlex2)
31:  {
32:       System.err(this.getClass().getName() + 
33:       ".mymethod - cannot close SQL connection : " + 
34:       sqlex2.toString());
35:  }
36:
37:  if (out != null) {
38:    try {
39:        out.close();
40:    }
41:    catch(IOException ioex2)
42:    {
43:       System.err(this.getClass().getName() + 
44:       ".mymethod - cannot close outfile" + 
45:       ioex2.toString());
46:    }
47:  }   
48:}

 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.