tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "German Augusto Niebles Alvarez" <GERMN...@susalud.com.co>
Subject Re: Filters, MVC, ResultSets
Date Mon, 28 Oct 2002 23:01:22 GMT
I suggest you use vectors and beans (collection of beans) to poblate rs
and then close de resultset, and use a class to connect to database
(jdbchelper class), i send you an example:
================================================


  // Obtiene la informacion acerca de la empresa
  public Vector obtenerInformacionOrganizacion()
              // throws SQLException,javax.naming.NamingException
  {

    Vector contenedorRazonSocial = new Vector();

    Connection connection = null;
    String selectRazonSocialStr =
      "SELECT * FROM tblRazonSocial";

    PreparedStatement selectStatement = null;

    try {

      // Obtiene una conexion a la base de datos, requiere Try
      connection = jdbcAccess.getConnection();

      // Prepara la sentencia de Busqueda
      selectStatement =
connection.prepareStatement(selectRazonSocialStr);

      // Obtiene el resultset
      ResultSet rs = selectStatement.executeQuery();

      // Si el rs tiene next es que tiene un registro con la informacion
acerca de la empresa

      FachadaRazonSocialBean facRazonSocialBean;

      if (rs.next()) {

        facRazonSocialBean = new FachadaRazonSocialBean();

        facRazonSocialBean.setNit(rs.getString("nit"));
        facRazonSocialBean.setNombre(rs.getString("nombre"));
        facRazonSocialBean.setDireccion(rs.getString("direccion"));
        facRazonSocialBean.setTelefono(rs.getString("telefono"));
        facRazonSocialBean.setEMail(rs.getString("email"));
       
facRazonSocialBean.setDireccionWeb(rs.getString("direccionWeb"));
        facRazonSocialBean.setCodigoIAC(rs.getString("codigoIAC"));

        contenedorRazonSocial.add(facRazonSocialBean);

      }
      contenedorRazonSocial.trimToSize();

      // Cierra el Resultset
      rs.close();
      jdbcAccess.cleanup(connection, selectStatement,null);

    }

    // Area de obtencion de Excepciones
    catch(NamingException ne) {
      System.out.println("NamingException in JDBCAccess :" + ne);
    }

    catch (SQLException sqle) {
   System.out.println("SQLException in JDBCAccess:" + sqle);
 }

 catch (Exception e)
 {
   System.out.println("Exception In JDBCAccess:" + e);
 }
    finally {
    return contenedorRazonSocial;

    }
  }



======================================================

Atentamente,


Germán Niebles
Analista de Información
Tel 4-93-86-00 Ext 7053

>>> hookomjj@uwec.edu 10/28 4:39 p.m. >>>
Hey All,

Everyone says for performance purposes, working directly with the
resultset is optimal.  But, with MVC, we can't just push the RS to the
JSP to display and ignore closing.

Is it possible with Filters to do a M->C1->V->C2 where C1 sets
resultsets in the request, then pushes the response up to the JSP to
render the content and then closes the resultset after rendering.  I
know 'programatically' it would work, but, I'm wondering about
exceptions and making sure that the resultsets get closed.  An example
would be passing the request/response to the JSP, but then an exception
occurs up the chain, does the exception trickle back down through the
filters no matter what to catch and close my JDBC items?

Best Regards,
Jacob Hookom

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message