日期:2014-05-19 浏览次数:20695 次
protected interface RestSet{ public void close(); public boolean next(); public String getString(String s) throws SQLException; public String getString(int i) throws SQLException; public int count(); } protected RestSet _select(final String sql){ try { return new RestSet(){ Statement __stt=__conn.createStatement(); ResultSet __rs=__stt.executeQuery(sql); public void close(){ try{ if(__rs!=null){ __rs.close(); } if(__stt!=null){ __stt.close(); } } catch(SQLException e){ System.out.println("语句或结果集关闭失败"); e.printStackTrace(); } } public boolean next(){ try { return __rs.next(); } catch (SQLException e) { //不处理 } return false; } public String getString(String s) throws SQLException{ return __rs.getString(s); } public String getString(int i) throws SQLException{ return __rs.getString(i); } public int count(){ try { __rs.last(); int r=__rs.getRow(); __rs.beforeFirst(); return r; } catch (SQLException e) { //不处理 } return 0; } }; } catch (SQLException e) { System.out.println(sql); e.printStackTrace(); } return null; }