|
代码段1 public static void listEmployees(String empSalary) throws SQLException { EmpIteratorClass empIterator; Integer salary = new Integer(empSalary); try { #sql empIterator = { select Ename, Job, HireDate from Emp where Sal > :salary }; while (empIterator.next()) { System.out.println("Name: " + empIterator.Ename()); System.out.println("Job: " + empIterator.Job()); System.out.println("Hire Date:" + empIterator.HireDate().toString()); } empIterator.close(); } catch (SQLException e) { System.err.println("SQLException" + e); System.exit(1); } } 代码段2 public static void listEmployees(String empSalary) throws SQLException { EmpIteratorClass empIterator; Integer salary = new Integer(empSalary); /*主机变量 */ String name = null; String job = null; Timestamp hireDate = null; try { #sql empIterator = { select Ename, Job, HireDate from Emp where Sal > :salary }; while (true) { #sql { FETCH :empIterator INTO :name, :job, :hireDate }; if (empIterator.endFetch()) { break; }
System.out.println("Name: " + name); System.out.println("Job: " + job); System.out.println("Hire Date:" + hireDate().toString()); } empIterator.close(); } catch (SQLException e) { System.err.println("SQLException" + e); System.exit(1); } }
|