Skip to main content

Posts

Showing posts with the label ResultSet

How to Use Updatable ResultSet in JDBC?

-- A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. An updatable result set allows modification to data in a table through the result set. The following code makes a result set that is scrollable and insensitive to updates by others: try { // Create a statement that will return updatable result sets Statement stmt = connection.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); //Primary key EmployeeID must be specified //so that the result set is updatable ResultSet resultSet = stmt.executeQuery( "SELECT EmployeeID, Name, Office FROM employees"); } catch (SQLException e) { } The updatable result se...

How to Use ResultSetMetaData to Learn ResultSet Information?

-- To query an unknown result set for information about the columns that it contains, you need to use ResultSetMetaData methods to determine the characteristics of the ResultSets before you can retrieve data from them. ResultSetMetaData methods provide the following types of information: getColumnCount() method returns the number of columns in the ResultSet getTableName() method returns the qualifier for the underlying table of the ResultSet getSchemaName() method returns the the designated column's table's schema name Information about a column, getColumnName() returns column name, getColumnTypeName() method returns the data type, getColumnDisplaySize() method returns column display length, getPrecision() method returns the column precision, and getScale() method returns scale. Whether a column is read-only, nullability, automatically numbered, and so on.