예제 #1
0
 public static ConjuntoResultado ejecutaQuery(String query, ArrayList<Parametro> parametros)
     throws Exception {
   ResultSet rs = null;
   PreparedStatement ptrs = null;
   ConjuntoResultado conj = new ConjuntoResultado();
   Connection con = null;
   try {
     con = Conexion.conexion().getConnection();
     ptrs = con.prepareStatement(query);
     for (Parametro parametro : parametros) {
       ptrs.setObject(parametro.getPosicion(), parametro.getValor());
     }
     rs = ptrs.executeQuery();
     conj.Fill(rs);
     rs.close();
     ptrs.close();
   } catch (SQLException exConec) {
     throw new RuntimeException(exConec);
   } finally {
     try {
       if (con != null) {
         if (!(con.isClosed())) con.close();
       }
     } catch (Exception ex) {
       throw new RuntimeException(ex);
     }
   }
   return conj;
 }
예제 #2
0
  public static ConjuntoResultado ejecutaQuery(String query) throws Exception {
    ResultSet rs = null;
    PreparedStatement pst = null;
    ConjuntoResultado conj = new ConjuntoResultado();
    Connection con = null;
    try {
      con = Conexion.conexion().getConnection();
      pst = con.prepareStatement(query);
      rs = pst.executeQuery();
      conj.Fill(rs);
      rs.close();
      pst.close();
    } catch (SQLException exConec) {
      throw new RuntimeException(exConec);
    } finally {
      try {
        if (con != null) {
          if (!(con.isClosed())) con.close();
        }
      } catch (Exception ex) {
        throw new RuntimeException(ex);
      }
    }

    return conj;
  }