代码清单1: A JAX-RPC service的实现


1  public class EmpImpl implements ServiceLifecycle, EmpInterface { 

2  ...
3    public void init(Object p0) throws ServiceException {
4    // Some logic to do upon service creation
5    }
6    public void destroy() {
7    // Some logic to do on service destruction - e.g. clean up JDBC
8    }

9  
10   public String getEmpSalary(String empNo) throws RemoteException {
11    String salary = "";
12    try {
13      conn = getConnection(dsName);
14      ps = conn.prepareStatement("SELECT SAL FROM EMP WHERE EMPNO = ?");
15      ps.setString(1, empNo);
16      ps.executeQuery();

17      ResultSet rs = ps.getResultSet();
18      if (rs.next()) {
19        salary = new String(rs.getBigDecimal(1).toString());
20      }
21    } catch (SQLException e) {
22    throw new RemoteException(e.getMessage());
23    } 
24    return salary;
25   }

...
E-mail this page