JDBC 4 Annotation Example using Select Query
Here’s an example of Select annotation to get all the active loans from the loan database:
1 2 3 4 |
interface LoanAppDetailsQuery extends BaseQuery { @Select("SELECT * FROM LoanDetais where LoanStatus = 'A'") DataSet<LoanApplication> getAllActiveLoans(); } |
The sql annotation allows I/O parameters as well (a parameter marker is represented with a question mark followed by an integer). Here’s an example of a parameterized sql query.
1 2 3 4 |
interface LoanAppDetailsQuery extends BaseQuery { @Select(sql="SELECT * from LoanDetails where borrowerFirstName= ?1 and borrowerLastName= ?2") DataSet<LoanApplication> getLoanDetailsByBorrowerName(String borrFirstName, String borrLastName); } |