10.07.2015 Views

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Step 5: Process the ResultSet objectOnce you execute your query, use the next() method of your ResultSetobject to iterate through the results. This method loops through the result setrow by row, detecting the end of the result set when it is reached.To pull data out of the result set as you iterate through it, use the variousgetXXX() methods of the ResultSet object, where XXX corresponds to aJava datatype.For example, the following code will iterate through the ResultSet objectrset from the previous section, and will retrieve and print each resort name:while (rset.next())System.out.println (rset.getString(1));The next() method returns false when it reaches the end of the result set.The resort names are materialized as Java Strings.Step 6: Close the ResultSet and Statement ObjectsYou should explicitly close the ResultSet and Statement objects after youfinish using them. This applies to all ResultSet and Statement objects youcreate when using the <strong>Cincom</strong> ORDB <strong>JDBC</strong> driver. Although the driver hasfinalize methods that will perform the cleanup, applications should explicitlyclose ResultSet and Statement objects in order to release resources assoon as possible.For example, if your ResultSet object is rset and your Statement objectis stmt, close the result set and statement with these lines:rset.close()stmt.close();When you close a Statement object that a given Connection objectcreates, the connection itself remains open.Step 7: Close the ConnectionYou must close your connection to the database once you finish your work. Usethe close() method of the Connection class to do this. For example, ifyour Connection object is conn, close the connection with this statement:conn.close();<strong>JDBC</strong> <strong>Developer's</strong> <strong>Guide</strong>, P25-9504-03 Page 23Chapter: 3. Basic FeaturesSection: First steps in <strong>JDBC</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!