'navigation' through records by id
Posted in 1998
hi all, i am trying to optimize my record navigation queries to improve overall program performance. each data object in my program (java app) has a next, prev and home method that can be redefined to allow the object type to decide how to move around from record to record. the data object is the base class used for any serious database objects in my program. each table has a id field that is serial (auto incremented for each record) here is the default implementation for prev // public method to get the previous record of this type public void prev() { int nav_id = navQuery("select id from "+tableName+" where id < "+db_id+" order by id DESC"); if (nav_id !=0) { load(nav_id); } } navQuery accepts a sql query string and always returns the first field of the query result as a integer. it only returns one record. the select statement for next() would is "select id from "+tableName+" where id > "+db_id+" order by id " is there a faster or better way to do this? id is indexed but i think the 'order by' part of the statement is taking up the most time. everything is very dynamic so i don't think i could use stored procedures or precompled statements unless the subclasses created them in it's constructor if not found when instigated. (table name is defined by the subclass) thanks, ~Scott -- ________________________________________ Scott Ahten Code Wrangler Silent ) Planet scott@stage22.com http://www.stage22.com