|
||||||||||
| 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'
| Field Summary | |
(package private) java.util.List |
fromList
|
(package private) java.util.List |
intoList
|
(package private) DbTable |
table
|
(package private) DbExpr |
where
|
| Constructor Summary | |
(package private) |
DbUpdater(DbTable table)
|
| 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. |
(package private) java.lang.String |
getQueryString()
|
(package private) int |
setSqlValues(java.sql.PreparedStatement stmt,
int i)
|
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 |
| Field Detail |
DbTable table
java.util.List intoList
java.util.List fromList
DbExpr where
| Constructor Detail |
DbUpdater(DbTable table)
| Method Detail |
public void setWhere(DbExpr where)
where - The new where value
public void addColumn(DbColumn into,
java.lang.Object from)
into - The column to update.from - The new value.
public int execute(DbConnection dbcon)
throws DbException
dbcon - Description of Parameter
DbException - Description of Exception
public int execute()
throws DbException
DbException - Description of Exception
int setSqlValues(java.sql.PreparedStatement stmt,
int i)
throws DbException,
java.sql.SQLException
DbException
java.sql.SQLException
java.lang.String getQueryString()
throws DbException
DbException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||