> List of tutorials for developing a Fat-Client

Code for Data-Base-Access (DBA) Object for a set of records from the table 'Project' – Java Fat Client Development

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes your rights or you think that rights of others (third parties) are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2007-01-11

This is document contains the code for Class JS_ErrDB_Project_Set_DBA.
For easy 'cut and paste' ;-)

package js_errdb.dba;

import java.sql.*;
import
js_errdb.dba.JS_ErrDB_Project_DBA;


import js_base.dba.*;
import js_base.structures.JSBS_MinimalParameters;


/**
 
*
 * @author
kurt@javascout.biz
 * @date 2007-01-11
 *
 * @description
 *  Data-Base-Access (DBA) Object to read a set of data from the table 'Project'.
 *
 *  Please see the description at the variables-declaration
.
 *
 *  User-Key: ProjectCode & LanguageCode
.

 
*
 * @change-log
 * when         who               why
 * --------------------------------------------------------
 *
 */

public class JS_ErrDB_Project_Set_DBA extends JSBS_DBA_Set {
/*
 * --------------------
 * Method to read all valid (at the given date) records from the table Project'. */
    public synchronized void getAllValidProjectLanguageCombinations(
                                 Connection parmDBCon, JSBS_MinimalParameters parmMinParm) {
/*
 * Build the SQL-statement.
 * Use the CONSTANTs to avoid typing errors !
 * The Command is put into an extra String (and not into the prepareStatement method)
 * to see more clearly what the command is.
*/
      final String locstrSQLCommand =
          JS_ErrDB_Project_DBA.
CONST_SELECT_ALL_ATTRIBUTES +
          " where " + JS_ErrDB_Project_DBA.CONST_ValidTill
+ " >=?" +
          " order by " + JS_ErrDB_Project_DBA.CONST_ProjectCode
+
", " +
                         JS_ErrDB_Project_DBA.CONST_LanguageCode + ", " +
                         JS_ErrDB_Project_DBA.CONST_ValidFrom + ", "
+
                         
JS_ErrDB_Project_DBA.
CONST_ValidTill + " desc"
;

/* Convert the actual date to the SQL-format. */
      Date locdteActualDate = new Date(parmMinParm.calWorkDate.getTime().getTime());
/* 'PreparedStatement'; a special class for operations toward the database. */
      PreparedStatement SQLStatement;
      try {
/* Construct the 'PreparedStatement' and fill it with the SQL-command. */
        SQLStatement = parmDBCon.prepareStatement(locstrSQLCommand);
/* Fill the variable(s) in the 'PreparedStatement'. */
        SQLStatement.setDate(1, locdteActualDate);
/* Perform the database-operation for SELECT. */
        ResultSet SQLResultSet = SQLStatement.executeQuery();
/* 
 * Transfer the data from the ResultSet to the vector used for returning data. */
        vecRecordSet.removeAllElements();
        for (;;) {
/* Read one record after the other from the ResultSet */
          if (!SQLResultSet.next()) return;
/* Check if the validity is not in the future.
 * Variables an method are defined in the inherited class. */
          locdteReadValidFrom = SQLResultSet.getDate(JSBS_DBA.CONST_ValidFrom);
          locdteReadValidTill = SQLResultSet.getDate(JSBS_DBA.CONST_ValidTill);
          if (isWithinDateRange(locdteActualDate, locdteReadValidFrom, locdteReadValidTill)) {
/* SQL-record within date-range;
 * construct a object corresponding to one SQL-record (the DBA-object) and
 * transfer the data using the method of the constructed class. */
            JS_ErrDB_Project_DBA locstructJS_ErrDB_Project_DBA = new JS_ErrDB_Project_DBA();
            locstructJS_ErrDB_Project_DBA.getValuesFromSQLResultSet(SQLResultSet);

/* Add this structure to the vector with the resulting DBA-objects.
 * This vector is defined in the inherited class. */
            
vecRecordSet.addElement(locstructJS_ErrDB_Project_DBA);
          }

        }
      }
      catch (SQLException SQLExc) {
/* An error occured while running the DB-operation; get the textual message. */
        ErrorMsg = SQLExc.getMessage();
      }
    }
}