db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "bhiyavudh" <bhiyav...@hotmail.com>
Subject Peer class executeQuery method
Date Sun, 03 Aug 2003 03:03:00 GMT
Hi All,
   I am a new torque user and  have just try making a query using peer class' executeQuery"
method by passing sql string as its parameter. I do get the list of record objects back but
when i try to iterate through these record objects and cast it to the bean object automatically
generated by torque, the exception was thrown with message = null. I have try using simple
criteria and it work fine. But for flexibility reason i would like to pass query string directly
as well. My smaple code is  listed below.


import java.util.*;
import com.gistec.webentrytool.*;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.TorqueRuntimeException;
import org.apache.torque.util.Criteria;

public class TestAddressTemplate {
    
       
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
      /*
       * Initializing Torque
       */
             Torque.init("C:\\torque\\torque-3.0.2\\Torque.properties");
             AddressOrg addressObj = new AddressOrg();
             AddressOrg first = new AddressOrg();
             first.setIdAddressOrg(1);
             first.setRporgname("Bookey GmbH");
             first.setDelpoint("Bookey Strasse 5");
             first.setCity("Bad konig");
             first.save();
           //  first.setCity("Frankfurt");
           //  AddressOrgPeer.doUpdate(first);
             

           //  AddressOrgPeer.doDelete(first);
           String sqlString = "select ID_ADDRESS_ORG, RPORGNAME, DELPOINT, CITY from ADDRESS_ORG";
 
           List addressOrgList = null;
           addressOrgList = AddressOrgPeer.executeQuery(sqlString);
          // Criteria crit = new Criteria();
          // Criteria newCrit = crit.addAscendingOrderByColumn(AddressOrgPeer.ID_ADDRESS_ORG);
          // addressOrgList = AddressOrgPeer.doSelect(crit);
           List subList = addressOrgList.subList(11, 16);
           //Iterator i = addressOrgList.iterator();
           Iterator i = subList.iterator();
           System.out.println(addressOrgList.size());
           while (i.hasNext()) {
               AddressOrg addressOrgObj = (AddressOrg) i.next();
               // Exception occurs on the line above when using peer class' executeQuery method

               System.out.println("ID_ADDRESS_ORG: " + addressOrgObj.getIdAddressOrg() + "\n");
          
               System.out.println("RPORGNAME: " + addressOrgObj.getRporgname() + "\n");
               System.out.println("DELPOINT:  " + addressOrgObj.getDelpoint() + "\n");
               System.out.println("CITY: " +   addressOrgObj.getCity() + "\n");
          }   
        }
        catch (TorqueException e) {
            System.out.println(e.getMessage());
        }
        catch (TorqueRuntimeException e) {
            System.out.println(e.getMessage());
        }
        catch(Exception e) {
            System.out.println(e.getMessage());
        }

    }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message