package dbcontroller;
import java.sql.SQLException;
import java.io.Serializable;
import java.util.Iterator;
import java.util.HashMap;
import javax.sql.RowSet;
import org.apache.beehive.controls.api.bean.ControlExtension;
import dbControl.DatabaseControl;
import dbControl.DatabaseControl.ConnectionDataSource;
import dbControl.DatabaseControl.SQL;
import forms.Employee;
@ControlExtension
@ConnectionDataSource(jndiName="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Test;user=sa;password=sa") //配置数据库连接属性
public interface MyFirstDBControl extends DatabaseControl
{
@SQL(statement="CREATE TABLE Employee (id INT PRIMARY KEY NOT NULL, " +
"name VARCHAR(50), age INT)")
public void createTable() throws SQLException;
@SQL(statement="DROP TABLE Employee")
public void dropTable() throws SQLException;
@SQL(statement="INSERT INTO Employee " + "(id, name, age) " +
"VALUES ({u.id}, {u.name}, {u.age})")
public void insertEmployee(Employee u) throws SQLException;
@SQL(statement="UPDATE Employee SET age = {age} WHERE id = {id}")
public void changeTitle(int id, String title) throws SQLException;
@SQL(statement="DELETE FROM Employee WHERE id = {id}")
public void deleteEmployee(int id) throws SQLException;
@SQL(statement="SELECT name FROM Employee")
public String[] selectAllName() throws SQLException;
@SQL(statement="SELECT * FROM Employee WHERE id={id}")
public Employee selectEmployee(int id) throws SQLException;
@SQL(statement="SELECT * FROM Employee ORDER BY id")
public Employee[] selectEmployees() throws SQLException;
@SQL(statement="SELECT * FROM Employee ORDER BY id", iteratorElementType=Employee.class)
public Iterator selectEmployeesWithIterator() throws SQLException;
@SQL(statement="SELECT * FROM Employee ORDER BY id")
public HashMap selectEmployeeWithHashMap() throws SQLException;
@SQL(statement="SELECT * FROM Employee ORDER BY id", maxRows=1)
public Employee[] selectOneEmployee() throws SQLException;
@SQL(statement="select count(*) from Employee")
public Integer getCount() throws SQLException; //返回int型的一定要定义返回类型为Integer
} |