The SELECT statement allows you to retrieve information from the database. When you execute a SELECT statement, the PreparedStatement.executeQuery method returns a ResultSet object.
Prepare a new SQL statement as a String.
String sql_string = "SELECT * FROM Department ORDER BY dept_no"; |
Pass the String to the PreparedStatement.
PreparedStatement select_statement = conn.prepareStatement(sql_string); |
Execute the statement and assign the query results to a ResultSet.
ResultSet cursor = select_statement.executeQuery(); |
Traverse through the ResultSet and retrieve the data.
// Get the next row stored in the ResultSet. cursor.next(); // Store the data from the first column in the table. int dept_no = cursor.getInt(1); // Store the data from the second column in the table. String dept_name = cursor.getString(2); |
Close the ResultSet to free resources.
cursor.close(); |
Close the PreparedStatement to free resources.
select_statement.close(); |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |