We are using struts and following DAO pattern.

This is the code


public String getCountryName(long ipSum){
        String name = null;
       Connection connection = null;
       PreparedStatement pstmt = null;
       ResultSet rs = null;

       try{
             connection = dataSource.getConnection();
             pstmt = connection.prepareStatement("select country_name from
ip_to_geo where ? between ip_from and ip_to");
             pstmt.setString(1, ""+ipSum);
             rs = pstmt.executeQuery();
             if( rs.next() ){
                name = rs.getString(1);
             }

        }catch(Exception ex){
               ex.printStackTrace();
        }finally{
           try{if( rs!=null)rs.close();}catch(SQLException
ex){ex.printStackTrace();}
           try {if( pstmt != null)pstmt.close();} catch (SQLException ex)
{ex.printStackTrace();}
           try {if( connection != null)connection.close();} catch
(SQLException ex) {ex.printStackTrace();}
             connection = null;
             pstmt = null;
              rs = null;
         }

return name;

}

Reply via email to