|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javatools.db.DbUpdater
A class used to update records from SQL tables. The constructor is not public. To obtain a DbUpdater call DbTable.updater(); Example: To update all the people who are (younger than 18 or older than 80) and whose name is "Fred"... to have a favourite_team of "Raiders";
DbDatabase db = ...; DbTable people = db.getTable("PEOPLE"); DbUpdater updater = people.deleter(); updater.addColumn(people.getColumn("FAVOURITE_TEAM"), "Raiders"); updater.setWhere(people.getColumn("AGE").lessThan(new Integer(18)).or( people.getColumn("AGE").greaterThan(new Integer(80))).and( people.getColumn("NAME").equal("FRED")); int numberOfPeopleUpdated = updater.execute();This is equivilent to...
UPDATE PEOPLE SET FAVOURITE_TEAM='Raiders' WHERE (AGE < 18 OR AGE > 80 ) AND NAME='Fred'Note the use of equal(), NOT equals(). To get more fancy, to update the same group of people to have a favourite team the same as Bill's team, we use a sub-select...
DbDatabase db = ...; DbTable people = db.getTable("PEOPLE"); DbSelector bills_team = db.selector(); bills_team.addColumn(people.getColumn("FAVOURITE_TEAM")); bills_team.setWhere(people.getColumn("NAME").equal("BILL")); DbUpdater updater = people.deleter(); updater.addColumn(people.getColumn("FAVOURITE_TEAM"), bills_team); updater.setWhere(people.getColumn("AGE").lessThan(new Integer(18)).or( people.getColumn("AGE").greaterThan(new Integer(80))).and( people.getColumn("NAME").equal("FRED")); int numberOfPeopleUpdated = updater.execute();This is equivilent to...
UPDATE PEOPLE SET FAVOURITE_TEAM=(SELECT FAVOURITE_TEAM FROM PEOPLE WHERE NAME='Bill') WHERE (AGE < 18 OR AGE > 80 ) AND NAME='Fred'
Method Summary | |
void |
addColumn(DbColumn into,
java.lang.Object from)
Add a column specification to update. |
int |
execute()
Execute this command on the default connection. |
int |
execute(DbConnection dbcon)
Execute this delete command on a specific connection. |
void |
setLists(java.util.List pIntoList,
java.util.List pFromList)
Sets in one time the column list and the value list. |
void |
setWhere(DbExpr where)
Set the where condition on which records to update. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public void setWhere(DbExpr where)
where
- The new where valuepublic void addColumn(DbColumn into, java.lang.Object from)
into
- The column to update.from
- The new value.public void setLists(java.util.List pIntoList, java.util.List pFromList)
pIntoList
- The column list.pFromList
- The value list.public int execute(DbConnection dbcon) throws DbException
dbcon
- The connection to use.
DbException
- If something goes wrong.public int execute() throws DbException
DbException
- If something goes wrong.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |