ResultSet: isFirst() : ResultSet : java.sql : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP
Java by API Home »  java.sql   » [  ResultSet  ]   
 



ResultSet: isFirst()

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {

  public static void main(String[] argsthrows Exception {
    try {
      String url = "jdbc:odbc:yourdatabasename";
      String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
      String user = "guest";
      String password = "guest";

      Class.forName(driver);
      Connection connection = DriverManager.getConnection(url, user, password);

      Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

      String sqlQuery = "SELECT EMPNO, EName, Job, MGR, HIREDATE FROM EMP";

      ResultSet rs = stmt.executeQuery(sqlQuery);

      int rowSize = 0;
      while (rs.next()) {
        rowSize++;
      }

      System.out.println("Number of Rows in ResultSet is: " + rowSize);
      if (rowSize == 0) {
        System.out.println("Since there are no rows, exiting...");
        System.exit(0);
      }

      int cursorPosition = Math.round(rowSize / 2);

      System.out.println("Moving to position: " + cursorPosition);
      rs.absolute(cursorPosition);
      System.out.println("Name: " + rs.getString(2));

      rs.relative(-1);

      cursorPosition = rs.getRow();
      System.out.println("Moving to position: " + cursorPosition);
      System.out.println("Name: " + rs.getString(2));

      System.out.println("Moving to the first row");
      while (!rs.isFirst()) {
        rs.previous();
      }
      System.out.println("Name: " + rs.getString(2));
      connection.close();
    catch (Exception e) {
      System.err.println(e);
    }
  }
}
           
       
Related examples in the same category
1.  ResultSet.CONCUR_UPDATABLE
2.  ResultSet.TYPE_SCROLL_SENSITIVE
3.  ResultSet: absolute(int row)
4.  ResultSet: close()
5.  ResultSet: deleteRow()
6.  ResultSet.getAsciiStream(int columnIndex)
7.  ResultSet: getBlob(String colName)
8.  ResultSet: getConcurrency()
9.  ResultSet: getInt(String columnName)
10.  ResultSet: getRow()
11.  ResultSet: getString(int columnIndex)Has Download File
12.  ResultSet: getTimestamp(int columnIndex)
13.  ResultSet: getType()
14.  ResultSet: insertRow()
15.  ResultSet: last()
16.  ResultSet: moveToInsertRow()
17.  ResultSet: next()
18.  ResultSet: previous()
19.  ResultSet: relative(int rows)
20.  ResultSet: updateRow()
21.  ResultSet: updateDouble(int columnIndex, double x)
22.  ResultSet: updateString(String columnName, String x)
23.  ResultSet: wasNull()
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.