This example shows how to use EasyORM to retrieve records for a single table. The method getRecordsForSingleTable() implements paging for several popular databases including PostgreSQL, MySQL, SQL Server, Oracle and DB2.

Simple select example code:

ConnectionPool connPool = ConnectionPool.getInstance(jdbcDriver, jdbcURL, user, password);
DBSelect dbSelect = new DBSelect();
//This method, by default, returns 10 records if the third parameter is left 0 (here recCount is set to 5)
// the id parameter indicates the column to use for sorting (necessary for paging)

List<EmployeeDB> employeeList = dbSelect.getRecordsForSingleTable(EmployeeDB.class, 0, 0,"id");

Run this example

Sometimes you want to retrieve a single value from a database (e.g. getting a record count etc). For this you can use the getScalarValueForCustomQuery method, which returns a single object. This object, however, can only be a simple object such as a String, Integer, Float etc. The method returns only the first record and can throw an exception if multiple records are found (depending on how it's called).


Retrieving a single value example:

ConnectionPool connPool = ConnectionPool.getInstance(jdbcDriver, jdbcURL, user, password);
DBSelect dbSelect = new DBSelect();
//This sql count method always return a single value. In PostgreSQL, the returned type is of type Long, though some RDBMS may return Integer)
String query="select count(id) from employee";
Long numEmployees = (Long)dbSelect.getScalarValueForCustomQuery(query, true);