JavaXT
|
|||||||||||||||
Recordset ClassUsed to query and update records in a database.
Constructors Recordset( )
PropertiesEOF Returns true if the current record position is after the last record, otherwise false.
Public MethodsisOpen( ) returns boolean Returns true if the recordset is open. This method is only supported on Java 1.6 or higher. Otherwise, the method will return false. open( String sql, Connection conn ) returns java.sql.ResultSet Used to execute a query and access records in the database. Records fetched using this method cannot be updated or deleted and new records cannot be inserted into the database.
open( String sqlString, Connection connection, boolean ReadOnly ) returns java.sql.ResultSet Used to execute a query and access records in the database.
open( java.sql.ResultSet resultSet ) returns void Used to initialize a Recordset using a standard Java ResultSet setFetchSize( int fetchSize ) returns void This method changes the block fetch size for server cursors. This may help avoid out of memory exceptions when retrieving a large number of records from the database. Set this method BEFORE opening the recordset. setMaxRecords( int maxRecords ) returns void Sets the maximum number of records to process getConnection( ) returns Connection Returns the database connection used to create/open the recordset. commit( ) returns void Used to explicitly commit an sql statement. May be useful for bulk update and update statements, depending on the underlying DBMS. addNew( ) returns void Used to prepare the driver to insert new records to the database. Used in conjunction with the update method. update( ) returns void Used to add or update a record in a table. Note that inserts can be batched using the setBatch() method to improve performance. When performing batch inserts, the update statements are queued and executed only after the batch size is reached. setBatchSize( int batchSize ) returns void Used to set the number of records to insert or update in a batch. By default, this value is set to 1 so that records are inserted/updated one at a time. By setting a larger number, more records are inserted at a time which can significantly improve performance. getBatchSize( ) returns int Returns the number of records that will be inserted or updated in a batch. By default, this value is set to 1 so that records are inserted/ updated one at a time. setUpdateKeys( Object... keys ) returns void Used to identify unique fields in a table for updates. Typically, this is the primary key(s) or a column with a unique constraint. In most cases, you do not need to call this method when updating records. Instead, an attempt is made to find the primary keys for the table using recordset metadata. However, this lookup may slow things down a bit and doesn't work on tables that don't have a primary key.
setUpdateKey( Object key ) returns void Used to identify a unique field in a table for updates. Typically, this is the primary key or a column with a unique constraint. Please see setUpdateKeys() for more information.
getGeneratedKey( ) returns Value Returns an auto-generated key created after inserting a record in the database. If this Statement object did not generate any keys, an empty Value object is returned. getRecord( ) returns javaxt.sql.Record Returns field names and values as a javaxt.sql.Record getFields( ) returns Field[] Used to retrieve the an array of fields in the current record. getField( String FieldName ) returns Field Returns a specific field in the array of fields. Returns null if the field name is not found. getField( int i ) returns Field Returns a specific field in the array of fields. Returns null if the index is out of range. getValue( String FieldName ) returns Value Returns the Value associated with a given field. Note the if the field doesn't exist in the result set, the method will return still return a Value. You can use the isNull() method on the Value to determine whether the value is null. getValue( int i ) returns Value Returns the Value associated with a given field. Note the if the field doesn't exist in the result set, the method will return still return a Value. You can use the isNull() method on the Value to determine whether the value is null. isDirty( ) returns boolean Returns true if any of the fields have been modified. You can find which field has been modified using the Field.isDirty() method. Example:
if (rs.isDirty()){ for (javaxt.sql.Field field : rs.getFields()){ if (field.isDirty()){ String val = field.getValue().toString(); System.out.println(field.getName() + ": " + val); } } } setValue( String FieldName, Object FieldValue ) returns void Set Value with an Object value. setValue( String FieldName, boolean FieldValue ) returns void Set Value with a Boolean value setValue( String FieldName, double FieldValue ) returns void Set Value with a Double value next( ) returns boolean Used to move the cursor to the next record in the recordset. This method is used to scroll through records like this:
rs.open(sql, conn); while (rs.next()){ //Do something with the record. Example: System.out.println(rs.getValue(0)); } rs.close();This pattern is an alternative to the hasNext/moveNext flow. moveNext( ) returns boolean Used to move the cursor to the next record in the recordset. This method is used along with the hasNext() method to scroll through records like this:
rs.open(sql, conn); while (rs.hasNext()){ //Do something with the record System.out.println(rs.getValue(0)); //Move the cursor to the next record rs.moveNext(); } rs.close();This pattern is an alternative to the flow described in the next() method. move( int numRecords ) returns void Moves the cursor to n-number of rows in the database. Typically this method is called before iterating through a recordset. getRecordCount( ) returns long Used to retrieve the total record count. Note that this method may be slow. |