public static void select( DbConnection conn, String tblNames, String colNames, String qual, boolean distinct, String hint, DbOutputRecordSet rs) throws Exception { DbSelectStatement stmt = null; DbOutputRecord rec; try { if (rs.getMaxNumItems() > 0) { stmt = new DbSelectStatement(); if (conn.isAllowHint()) { /* String sql = */ stmt.create(conn, null, tblNames, colNames, qual, distinct, hint); } else { /* String sql = */ stmt.create(conn, null, tblNames, colNames, qual, distinct); } stmt.execute(); int count = 0; while (stmt.next() && count++ < rs.getMaxNumItems()) { rec = rs.newRecord(); rec.getStatementValues(stmt); } stmt.release(); } } catch (Exception e) { DbSelectStatement.ensureRelease(stmt, e); } }
public static void selectUnionAll( DbConnection conn, String tblNames1, String tblNames2, String colNames1, String colNames2, String qual1, String qual2, String orderBy, boolean distinct, DbOutputRecordSet rs) throws Exception { DbSelectStatement stmt = null; DbOutputRecord rec; int count = 0; try { if (rs.getMaxNumItems() > 0) { stmt = new DbSelectStatement(); String sql1 = stmt.create(conn, tblNames1, colNames1, qual1, distinct); String sql2 = stmt.create(conn, tblNames2, colNames2, qual2, distinct); String sqlUnion = "(" + sql1 + ")" + " UNION ALL " + "(" + sql2 + ")"; if (!StringUtils.isBlank(orderBy)) { sqlUnion += orderBy; } stmt.create(conn, sqlUnion); stmt.execute(); // int count = 0; while (stmt.next() && count++ < rs.getMaxNumItems()) { rec = rs.newRecord(); rec.getStatementValues(stmt); } stmt.release(); } } catch (Exception e) { DbSelectStatement.ensureRelease(stmt, e); } }
/** * Ejecuta la consulta que se le pasa * * @param conn * @param sql * @param rec * @throws Exception */ public static void select(DbConnection conn, String sqlCompleta, DbOutputRecordSet rs) throws Exception { DbSelectStatement stmt = null; DbOutputRecord rec; try { stmt = new DbSelectStatement(); stmt.create(conn, sqlCompleta); stmt.execute(); int count = 0; while (stmt.next() && count++ < rs.getMaxNumItems()) { rec = rs.newRecord(); rec.getStatementValues(stmt); } stmt.release(); } catch (Exception e) { DbSelectStatement.ensureRelease(stmt, e); } }