static String buildSelectSingleRowSql ( String databaseType , String table , String columns ) { switch ( databaseType ) { case SQL_SERVER_DB_TYPE : //syntax supported since SQLServer 2008 return "SELECT TOP(1) " + columns + " FROM " + table ; case ORACLE_DB_TYPE : return "SELECT " + columns + " FROM " + table + " FETCH NEXT 1 ROWS ONLY" ; case TERADATA_DB_TYPE : return "SELECT TOP 1 " + columns + " FROM " + table ; default : return "SELECT " + columns + " FROM " + table + " LIMIT 1" ; } }
Builds SQL SELECT to retrieve single row from a table based on type of database