Wednesday, April 28, 2010

List to XML

Iterator it = list.iterator();
while (it.hasNext()) {

Timesheet timesheet = (Timesheet) it.next();

Element row = doc.createElement("Row");
results.appendChild(row);
String columnName = null;

try {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
row.appendChild(getElementNode(doc, "RES_ID", Integer
.toString(timesheet.getRES_ID())));

row.appendChild(getElementNode(doc, "FULL_NAME", timesheet
.getFULL_NAME()));

row.appendChild(getElementNode(doc, "RES_UNIQUE_NAME",
timesheet.getRES_UNIQUE_NAME()));

row.appendChild(getElementNode(doc, "RES_OPEN", Integer
.toString(timesheet.getRES_OPEN())));

row.appendChild(getElementNode(doc, "TS_START", sdf.format(
timesheet.getTS_START()).trim()));

row.appendChild(getElementNode(doc, "TS_FINISH", sdf
.format(timesheet.getTS_FINISH()).trim()));

row.appendChild(getElementNode(doc, "TP_ID", timesheet
.getTP_ID()));

row.appendChild(getElementNode(doc, "TP_OPEN", CommonUtils
.convertBooleanToString(timesheet.isTP_OPEN())));

row.appendChild(getElementNode(doc, "RESOURCE_TYPE",
CommonUtils.convertBooleanToString(timesheet
.isRESOURCE_TYPE())));

row.appendChild(getElementNode(doc, "TS_ID", Integer
.toString(timesheet.getTS_ID())));

row.appendChild(getElementNode(doc, "TS_VERSION", Integer
.toString(timesheet.getVersion())));

row.appendChild(getElementNode(doc, "TS_STATUS", Integer
.toString(timesheet.getTS_STATUS())));

row.appendChild(getElementNode(doc, "TS_META_STATUS",
Integer.toString(timesheet.getTS_META_STATUS())));

row.appendChild(getElementNode(doc, "TS_HOURS", Double
.toString(timesheet.getTS_HOURS())));

row.appendChild(getElementNode(doc, "TS_IS_ADJUSTMENT",
CommonUtils.convertBooleanToString(timesheet
.isTS_IS_ADJUSTMENT())));

row.appendChild(getElementNode(doc, "BEING_ADJ",
CommonUtils.convertBooleanToString(timesheet
.isBEING_ADJ())));

row.appendChild(getElementNode(doc, "TS_IS_ADJUSTED",
CommonUtils.convertBooleanToString(timesheet
.isTS_IS_ADJUSTED())));

} catch (Exception ex) {
Element node = doc.createElement(columnName.toUpperCase());
node.appendChild(doc.createTextNode(""));
row.appendChild(node);
}

}

} catch (Exception e) {

e.printStackTrace();

}
return doc;
}

Result set to List

while(rset.next()){

TaskListPojo taskList = new TaskListPojo();

taskList.setPROJECT_NAME(rset.getString("Col_1"));

taskList.setPROJECT_ID(rset.getString("Col_2"));

taskList.setPROJECT_CODE(rset.getString("Col_3"));

taskList.setSATRT_DATE(rset.getDate("Col_4"));

taskList.setFINISH_DATE(rset.getDate("Col_5"));

taskList.setTASK_NAME(rset.getString("Col_6"));

taskList.setTASK_ID(rset.getInt("Col_7"));

taskList.setETC(rset.getString("Col_8"));

taskList.setUNIQUE_NAME(rset.getString("Col_9"));

taskList.setTASK_STATUS(rset.getString("Col_10"));

taskListObj.add(taskList);

}

JDBC Statemets Example

con = ConnectionManager.getInstance().getConnection();
proc = con.prepareCall("{call Z_MOBAPP_TASKLIST_SP(?,?,?,?,?,?,?,?,?,?)}");
proc.setString(1,userID); //P_USERID IN VARCHAR2
proc.setInt(2,timeSheetId); //P_TIMESHEETID IN NUMBER
proc.setString(3,taskname); //P_TASKNAME IN VARCHAR2

proc.setInt(7,pageLimit); //P_ROWS_PAGE IN NUMBER,
proc.setInt(8,pageNum); //P_PAGE_NUM IN NUMBER,
proc.setString(9,sortBy); //P_SORT_COL VARCHAR2,

proc.registerOutParameter(10,OracleTypes.CURSOR);
proc.executeUpdate();

Result set to XML data conversion

public static Document (ResultSet rs)
throws ParserConfigurationException, SQLException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
String ApplicationConfigurationData[] = new String[4];
ApplicationConfigurationData[1] = "say";
ApplicationConfigurationData[2] = "pulkam";

Element results = doc.createElement("Results");
doc.appendChild(results);

while (rs.next()) {
Element row = doc.createElement("Row");
results.appendChild(row);

for (int i = 1; i <= 2; i++) {
// String columnName = rsmd.getColumnName(i);
Object value = rs.getObject(i);

Element node = doc
.createElement(ApplicationConfigurationData[i]);
node.appendChild(doc.createTextNode(value.toString()));
row.appendChild(node);
}
}
return doc;
}