Using JDBC with Java Applications and Applets 80 (Web cam hosting)

Using JDBC with Java Applications and Applets 80 With the relative() method, the system moves the cursor using the current row as a pivot point. A positive parameter moves the internal cursor X number of rows from the current position. A negative parameter moves the internal cursor X number of rows back from the current position. If a value of 0 is passed to the method, the cursor will not move. As you might have guessed, using the method absolute(1) will move the cursor to the first row and the method absolute(-1) will move the cursor to the last row. Two methods for doing the same thing are first() and last(). These methods will move the cursor to the first and last rows in the ResultSet, respectively. It s even possible to move the cursor before the first row as well as after the last row. The beforeFirst() method moves the internal cursor to row 0, which is just before the first row. The method afterLast() moves the cursor to a position just after the last row. In most cases, though, you probably want to move through the ResultSet one row at a time. Just as we did in our example code in Listing 5.1, the next() method moves the cursor one row ahead at a time. Since the internal cursor starts before the first row, the next() method should be called before any processor starts on the ResultSet. Note that a default ResultSet is a forward- only data type; therefore, only the next() method should be valid. However, Connector/J has implemented the previous() method to work on any ResultSet object. In fact, there is even a prev() method defined in Connector/J for moving the cursor backward. In the cases of first(), last(), next(), and previous(), the methods all return a Boolean value indicating whether the command was successful. For first() and last(), the methods return false only when the ResultSet object is empty and therefore no first or last row exists. The methods next(), previous(), and Connector/J s prev() return false when there are no longer any valid rows left in the ResultSet. For example, next() returns true until the internal cursor points to the position after the last row. As you might have noticed, there is no method for determining the size of the ResultSet. We must rely on the Boolean values returned by the methods that move the internal cursor. There is a way to get the total size of a result from the database using a query, but it s a little more complex than the current topics we are discussing. We tackle that one in the next chapter. Getter Methods Once the cursor has been set on a particular row, the contents of each column can be obtained. In our example code, we pull the first column the column starting at 1 using the code System.out.println(rs.getString(1));
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

Comments are closed.