Mike, You missed the essence of Chris's suggestion:
"3. Throw an exception in your catch(SQLException) block." In other words, your catch block would "swallow" the SQLException should one occur. As written, the code cannot be compiled because there is no explicit return statement in the catch{} block. -Bob ----- Original Message ---- From: Michael Ni <[EMAIL PROTECTED]> To: users@tomcat.apache.org Sent: Wednesday, January 10, 2007 10:15:51 PM Subject: Re: [OT] a Collection of beans to store sql data hmmm there is a sqlexception in my catch block, unless i'm doing it wrong. mike >From: Christopher Schultz <[EMAIL PROTECTED]> >Reply-To: "Tomcat Users List" <users@tomcat.apache.org> >To: Tomcat Users List <users@tomcat.apache.org> >Subject: Re: [OT] a Collection of beans to store sql data >Date: Wed, 10 Jan 2007 21:15:50 -0500 > >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Michael, > >Michael Ni wrote: > > My problem is i get > > > > PersonNew.java:48: missing return statement > > } > >[snip] > > > public Collection getPersondata( String alias, String password ) { > > > > Connection conn = null; > > PreparedStatement stmt = null; > > ResultSet rs = null; > > Collection retValue = new ArrayList(); > > String query = "SELECT * FROM person WHERE alias = ?, password = ?"; > > try { > > conn = DBConnection.getDBConnection(); > > stmt = conn.prepareStatement( query ); > > stmt.setString( 1, alias ); > > stmt.setString( 2, password ); > > rs = stmt.executeQuery(); > > while (rs.next()) { > > PersonalInfo beanrow = new PersonalInfo(); > > beanrow.setAlias(rs.getString("alias")); > > beanrow.setPassword(rs.getString("password")); > > retValue.add(beanrow); > > > > } > > return retValue; > > } > > catch( SQLException sqle ) { > > sqle.printStackTrace(); > > } > > finally { > > try {if (rs != null) rs.close();} catch (SQLException e) {} > > try {if (stmt != null) stmt.close();} catch (SQLException e) {} > > try {if (conn != null) conn.close();} catch (SQLException e) {} > > } > > } > >The problem is that you have a code path that can exit your method >without returning a value (which is a no-no). If a SQLException is >thrown inside your try block, it will be caught, logged, and then the >method exists with no return value. > >You have several options: > >1. Put a catch-all "return" at the very end of the method > (after the finally block) >2. Put a return in your catch(SQLException) block. >3. Throw an exception in your catch(SQLException) block. > >I tend to favor #3 since a SQLException usually indicates a real problem >rather than something that is recoverable, but this may not be true >under your particular circumstances. > >- -chris > >-----BEGIN PGP SIGNATURE----- >Version: GnuPG v1.4.6 (MingW32) >Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > >iD8DBQFFpZ3V9CaO5/Lv0PARAuNvAKC4+g9iHyn6U3m88e+hgBJfQ87WjgCeJAV9 >sDq1+7kNLRWpyZrZE1roQ14= >=/ZcX >-----END PGP SIGNATURE----- > >--------------------------------------------------------------------- >To start a new topic, e-mail: users@tomcat.apache.org >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > _________________________________________________________________ Find sales, coupons, and free shipping, all in one place! MSN Shopping Sales & Deals http://shopping.msn.com/content/shp/?ctid=198,ptnrid=176,ptnrdata=200639 --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ____________________________________________________________________________________ Need a quick answer? Get one in minutes from people who know. Ask your question on www.Answers.yahoo.com --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]