Java Tutorial/Database/JDBC Annotation — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 05:06, 1 июня 2010
JDBC Annotations
The following table lists the Select annotation elements.
ElementTypeAccessibilitysql or valueStringThe SQL statement to be executedtableNameStringThe name of the table that will be updated when the DataSet.sync method is calledreadOnlybooleanIndicates the returned DataSet is read-onlyconnectedbooleanIndicates if the DataSet is connected to the data sourceallColumnsMappedbooleanIndicates if there is a one-to-one mapping between the column names in the SQL statement and the fields in the returned DataSetscrollablebooleanIndicates if the returned DataSet is scrollable. This element only takes effect only when in connected mode.
import java.sql.BaseQuery;
import java.sql.DataSet;
import java.sql.Select;
public interface UserQueries extends BaseQuery {
// Select all users
@Select (sql ="SELECT userId, firstName, lastName FROM Users",
readOnly=false, connected=false, tableName="Users")
DataSet<User> getAllUsers ();
// Select user by name */
@Select (sql ="SELECT userId, firstName, lastName FROM Users"
+ "WHERE userName=?", readOnly=false, connected=false,
tableName ="Users")
DataSet<User> getUserByName(String userName);
}
Update annotation
The Update annotation is used to decorate a method specifying an SQL update statement.
The method"s return value can be an int or void.
Only if the return value type is int will the update count be returned.
ElementTypeAccessibilitysql or valueStringThe SQL statement to be executedkeysGenerated KeysIndicates if autogenerated keys are returned. The default value is GeneratedKeys.NO_KEYS_RETURNED
import java.sql.BaseQuery;
import java.sql.DataSet;
import java.sql.Select;
public interface UserQueries extends BaseQuery {
// Delete user
@Update ("DELETE Users WHERE firstName={firstName}" +
"AND lastName={lastName}")
int deleteUser (String firstName, String lastName);
}