public static long selectMaxLong( DbConnection conn, String tblName, String colName, String alias, String qual) throws Exception { long val = 0; DbSelectStatement stmt = null; String stmtText; try { stmt = new DbSelectStatement(); if (qual == null) stmtText = "SELECT MAX(" + colName + ") AS " + alias + " FROM " + tblName; else stmtText = "SELECT MAX(" + colName + ") AS " + alias + " FROM " + tblName + " " + qual; stmt.create(conn, stmtText); stmt.execute(); if (stmt.next()) { val = stmt.getLong(1); stmt.release(); } /* * else throw new IeciTdException(DbError.EC_NOT_FOUND, * DbError.EM_NOT_FOUND); */ stmt.release(); if (val == DbDataType.NULL_LONG) val = 0; return val; } catch (Exception e) { DbSelectStatement.ensureRelease(stmt, e); throw e; } }
public static long selectMinString(DbConnection conn, String tblName, String colName, String qual) throws Exception { long val = 0; DbSelectStatement stmt = null; String stmtText; try { stmt = new DbSelectStatement(); if (qual == null) stmtText = "SELECT MIN(" + DBUtils.getNativeToNumberSyntax(conn, colName, 16) + ") AS " + colName + " FROM " + tblName; else stmtText = "SELECT MIN(" + DBUtils.getNativeToNumberSyntax(conn, colName, 16) + ") AS " + colName + " FROM " + tblName + " " + qual; stmt.create(conn, stmtText); stmt.execute(); if (stmt.next()) { val = stmt.getLong(1); stmt.release(); } stmt.release(); if (val == DbDataType.NULL_SHORT_INTEGER) val = 0; return val; } catch (Exception e) { DbSelectStatement.ensureRelease(stmt, e); throw e; } }
public static long selectLong(DbConnection conn, String tblName, String colName, String qual) throws Exception { long val = DbDataType.NULL_LONG; DbSelectStatement stmt = null; try { stmt = new DbSelectStatement(); /* String sql = */ stmt.create(conn, tblName, colName, qual, false); stmt.execute(); if (stmt.next()) { val = stmt.getLong(1); stmt.release(); return val; } else throw new IeciTdException(DbError.EC_NOT_FOUND, DbError.EM_NOT_FOUND); } catch (Exception e) { DbSelectStatement.ensureRelease(stmt, e); throw e; } }