suresh saro

Greenhorn
+ Follow
since May 22, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by suresh saro

Yes, I managed to sort.......as in the program below....But my requirement is, I have the List that needs to be sorted, which is a list of DTO's with an attribute inside that DTO. This attribute is the criteria for sorting my List and this list needs to be sorted as predefined in the list2...as in the program....Is it possible. If possible, how is it?? Can anyone please help me.......

import java.util.*;
public class TestUsingMe {
public static void main(String[] args) {
List list1 = new ArrayList();
list1.add("Named Non-Owner");
list1.add("Restored");
list1.add("Antique/Classic");

List list2 = new ArrayList();
list2.add("Private Passenger");
list2.add("Restored");
list2.add("Antique/Classic");
list2.add("Named Non-Owner");
list2.add("Trailer");

AppComparator appcomparator = new AppComparator(list2);
Collections.sort(list1, appcomparator);

System.out.println(list1);
System.out.println(list2);
}

static class AppComparator implements Comparator {
private List list;

public AppComparator(List list) {
this.list = list;
}

public int compare(Object o1, Object o2) {
return list.indexOf(o1) - list.indexOf(o2);
}
}
}
18 years ago
I want to sort the items in my list with a predefined order....Is it possible? I can sort my List using a natural sort as in the below example. But that is not am looking for.....Am looking for sorting my list using an already defined order which i can hold using another list. IS IT POSSIBLE USING Comparator

import java.util.*;

public class TestUsingMe {
static class AppComparator implements
Comparator {
public int compare(Object o1, Object o2) {
int cc = ((Integer)o1).compareTo(o2);
return (cc < 0 ? 1 : cc > 0 ? -1 : 0);
}
}

static Comparator appcomparator =
new AppComparator();

static void sort(List list1) {
Collections.sort(list1, appcomparator);
}

public static void main(String[] args) {
List list1 = new ArrayList();
list1.add(new Integer(90));
list1.add(new Integer(43));
list1.add(new Integer(21));

sort(list1);

System.out.println(list1);
}
}

Please reply................

[ June 05, 2006: Message edited by: suresh saro ]
[ June 09, 2006: Message edited by: suresh saro ]
18 years ago
Am trying to execute the below program:

Am getting the resultset as blank (i.e) []

CAN ANYONE PLEASE HELP ME ON THIS?
Thanks in Advance!!

public class AgentInfoDAOImpl extends BaseJdbcDAO implements AgentInfoDAO {
private static final Log log = LogFactory.getLog(AgentInfoDAOImpl.class);
private static final String RETURN_SUCCESS = "000";
private String dbSchema;
private AgencyProfileDTO agProfile;
private ProducerDetailsDTO prodDetails;
private Map input = new HashMap();
private String licenseStatus;

/**
* Uses the Inner Class StoredProcAGSIM028, to create the Database connection and execute the stored procedure.
* @see com.nationwide.ag.persistence.dao.jdbc.AgentInfoDA O#getProducerList(com.nationwide.ag.dto.AgInfoSear chCriteriaDTO)
*/
public ProducerDetailsDTO getProducerList(
AgInfoSearchCriteriaDTO agSCriteria) throws ResourceException {
StoredProcAGSIM028 storedProc = new StoredProcAGSIM028(getJdbcTemplate());

prodDetails = new ProducerDetailsDTO();
buildInput(agSCriteria, "AGSIM028");
storedProc.executeStoredProc(input);
return prodDetails;
}

private void buildInput(AgInfoSearchCriteriaDTO agSCriteria, String ticket) {
if (ticket.equals("AGSIM028")) {
input.put("I_AGCY", "00000869");
input.put("I_PRODUCER", "");
input.put("C_STATUS", "AC");
}
}

private DataAccessException buildDataAccessException(final Map inParams,
final org.springframework.dao.DataAccessException exception,
final String storedProcedureName) {
String msg = "Failed to execute stored procedure " +
storedProcedureName + " because of database reason " +
exception.getMessage();

DataAccessException dataException = new DataAccessException(msg,
ErrorCode.DEFAULT, exception);
dataException.addDataItem("inParams", inParams);
log.error(msg, exception);

return dataException;
}

/**
* @return Returns the dbSchema.
*/
public String getDbSchema() {
return dbSchema;
}

/**
* @param aDBSchema The dbSchema to set.
*/
public void setDbSchema(final String aDBSchema) {
dbSchema = aDBSchema;
}
private class StoredProcAGSIM028 extends StoredProcedure {
public static final String SQL = "AGSIM028";

/**
* Constructor to define the stored proc parameters (INPUT & OUTPUT).
* @param jdbcTemplate
*/
public StoredProcAGSIM028(final JdbcTemplate jdbcTemplate) {
super(jdbcTemplate, getDbSchema() + "." + SQL);
declareParameter(new SqlReturnResultSet("T_FIRST_NAME", new DataMapper()));
declareParameter(new SqlParameter("I_AGCY", Types.CHAR));
declareParameter(new SqlParameter("I_PRODUCER", Types.CHAR));
declareParameter(new SqlParameter("C_STATUS", Types.CHAR));
declareParameter(new SqlOutParameter("AG2_RC", Types.CHAR));
declareParameter(new SqlOutParameter("AG2_RC_CAUSE", Types.CHAR));
declareParameter(new SqlOutParameter("AG2_SQLCA", Types.CHAR));
declareParameter(new SqlOutParameter("AG2_SQLCODE",
Types.DECIMAL));
declareParameter(new SqlOutParameter("AG2_SQLCERM", Types.CHAR));
compile();
}

/**
* Executes the stored procs.
* @param inParams - a Map containing the input parameters to the stored procedure
* @throws DataAccessException when execution of stored procs fails
*/
public void executeStoredProc(final Map inParams)
throws DataAccessException {
Map out = null;
startTimer();

try {
out = execute(inParams);
List productList = (List) out.get("T_FIRST_NAME");
List l = (List)out.get("T_FIRST_NAME");
System.out.println(l);
} catch (org.springframework.dao.DataAccessException e) {
throw buildDataAccessException(null, e, SQL);
}
stopTimer("Execute Stored Proc...." + SQL);
}

}

/**
* DataMapper is an Inner class which implements the RowMapper.
*/
private class DataMapper implements RowMapper {
/**
* Method to map the ResultSet to the Object.
* @param ResultSet
* @param Number of Rows
*/
public Object mapRow(ResultSet rs, int rowNum)
throws SQLException {
return rs.getString("T_FIRST_NAME");
}
}
}
Am trying to execute the below program:

Am getting the resultset as blank (i.e) []

CAN ANYONE PLEASE HELP ME ON THIS?
Thanks in Advance!!