Using JDBC with Java Applications (Cheap hosting) and Applets 78

Using JDBC with Java Applications and Applets 78 outcome also produces a ResultSet, but instead the set is empty, which indicates that the query didn t produce any rows from the database. Displaying Results The example code takes the ResultSet produced by the execution of our query string and displays the first column of each row. As you see in the next section, the ResultSet object includes a host of methods for manipulating the rows and columns it currently stores. Using the ResultSet Object The ResultSet object is the primary storage mechanism for the rows returned from a query on the MySQL database. It is imperative that you have a full understanding of how the object works and how you get our data out of it. Conceptually, the ResultSet object looks like an adjustable two-dimensional array, as you can see in Figure 5.2. Internal pointer acc_id username password 1034033 jimmy hispassw 1034035 jdoe does Figure 5.2 The ResultSet object. As shown in Figure 5.2, the ResultSet object consists of rows containing data based on the information returned from the database query. The columns of the object are the fields from the database as specified in the query. If the query uses a * in the SELECT, then all of the columns from the database will be represented in the ResultSet. If only a few of the columns are listed in the SELECT, then only those columns will appear in the set. The ResultSet uses an internal cursor to keep track of what row data should be returned when the application requests data. The default behavior for a Result- Set is to maintain read-only data and allow the internal cursor to move forward through the rows. If the data needs to be used a second time, the cursor will need to be moved to the beginning. When a ResultSet object is first instantiated and filled, the internal cursor is set to a position just before the first row. A large number of getter methods are available for retrieving data from the ResultSet object. These methods pull data from a specific row/column cell and attempt to convert the data to a Java data type as defined by the getter method. See Chapter 7, MySQL Type Mapping, for a full discussion on mapping between MySQL, Connector/J, and Java.

Hint: This post is supported by Gama php5 hosting services

Comments are closed.