日期:2014-05-16 浏览次数:20533 次
//================================================== //公用代码 Connection cn = DBManager.getConn("jdbc:oracle:thin:u/p@dbs:1521:orcl"); String selectSQL = "SELECT COL1 FROM TB1"; //各方式代码…… DBManager.closeConn(cn);
//=================================================== //方式一:利用ResultSet的getRow方法 Statement stmt = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(selectSQL); rs.last(); logger.info("利用ResultSet的getRow方法:" + rs.getRow()); rs.close(); stmt.close();
//=================================================== //方式二:自行迭代方式 Statement stmt = cn.createStatement(); ResultSet rs = stmt.executeQuery(selectSQL); int i = -1; while (rs.next()) { i++; } logger.info("自行迭代方式:" + i); rs.close(); stmt.close();
//方式三:SELECT COUNT(*) FROM (SQL)方式 String newSQL = "SELECT COUNT(1) AS CT FROM (" + selectSQL + ")"; Statement stmt = cn.createStatement(); ResultSet rs = stmt.executeQuery(newSQL); rs.next(); logger.info("SELECT COUNT(1) AS CT FROM (SQL)方式:" + rs.getInt(1)); rs.close(); stmt.close();