Using Database Operations

The Query (Select) Operation

ProcedureTo perform a query operation on a table

  1. Execute the select() method with the “where” clause specified if necessary.


    Note –

    The content of the input.getText() file may contain null, meaning it will not have a “where” clause or it can contain a “where” clause such as empno > 50.


  2. Loop through the ResultSet using the next() method.

  3. Process the return record within a while() loop.

    For example:


    package prjDB2Connect_JCDjcdALL;
    
    
    public class jcdTableSelect
    {
    
        public com.stc.codegen.logger.Logger logger;
    
        public com.stc.codegen.alerter.Alerter alerter;
    
        public com.stc.codegen.util.CollaborationContext collabContext;
    
        public com.stc.codegen.util.TypeConverter typeConverter;
    
        public void receive( com.stc.connector.appconn.file.FileTextMessage
     input, dtd.otdOutputDTD1325973702.DB_Employee otdOutputDTD_DB_Employee_1,
     otdDB2Connect.OtdDB2ConnectOTD otdDB2Connect_1, com.stc.connector.
    appconn.file.FileApplication FileClient_1 )
            throws Throwable
        {
            FileClient_1.setText( "Selectiong records from db_employee table
     via Table Select........" );
            FileClient_1.write();
            otdDB2Connect_1.getDb_employee().select( input.getText() );
            while (otdDB2Connect_1.getDb_employee().next()) {
                otdOutputDTD_DB_Employee_1.setEmpNo( typeConverter.shortToString(
     otdDB2Connect_1.getDb_employee().getEMP_NO(), "#", false, "" ) );
                otdOutputDTD_DB_Employee_1.setLastname( otdDB2Connect_1.
    getDb_employee().getLAST_NAME() );
                otdOutputDTD_DB_Employee_1.setFirstname( otdDB2Connect_1.
    getDb_employee().getFIRST_NAME() );
                otdOutputDTD_DB_Employee_1.setRate( otdDB2Connect_1.
    getDb_employee().getRATE().toString() );
                otdOutputDTD_DB_Employee_1.setLastDate( typeConverter.
    dateToString( otdDB2Connect_1.getDb_employee().getLAST_UPDATE(),
     "yyyy-MM-dd hh:mm:ss", false, "" ) );
                FileClient_1.setText( otdOutputDTD_DB_Employee_1.marshalToString() );
                FileClient_1.write();
            }
            FileClient_1.setText( "Table Select Done." );
            FileClient_1.write();
        }
    
    }