Microsoft web hosting - Using the ResultSet Object 81 This code tells
Using the ResultSet Object 81 This code tells the ResultSet to return (as a String) the value located in the first column of the row the internal cursor is currently pointing to. Clearly, the cursor must be pointing to a valid row; otherwise, the getter method will throw a SQLException exception. Looking at the ResultSet API, you will notice that there are quite a large number of methods for obtaining values from the set. Each method is designed to pull a specific type, such as integer or string. As an example, consider the getString() methods: String getString(int columnIndex); String getString(String columnName); Both of these methods pull a value from MySQL as a String. Even if the value in MySQL is an integer, the integer will be coaxed into the String type. However, what we really want to consider are the parameters to the method. Notice how one of them is passing an integer and the other is a String. Let s look at an example of how the getters will work based on a real database. One of our sample databases is called accounts, and it contains a table named acc_acc. This table is defined as: acc_id - int username - varchar acc_id int username varchar password varchar ts timestamp act_ts - timestamp Using the getString() methods, we can pull the value contained in the username column in two different ways. First, we pull the values using some example SQL: ResultSet rs = statement.executeQuery(”SELECT * FROM acc_acc”); Now we know that the variable rs is a ResultSet and that its internal pointer is set at a position before the first row. To start pulling the data from the set, we need to move the internal pointer to the next row: rs.next(); With the internal pointer at the first row in the object, we can output the values in the username column by using the getString() method. Two different methods are available, as shown here: System.out.println(rs.getString(1)); System.out.println(rs.getString(”username”)); In the first output statement, the column number is used to let the ResultSet object know which column the value should be pulled from. In the second
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services