String callString = callStringBuffer.toString();
CallableStatement cstmt = con.prepareCall(callString);
DOMPrinter domPrinter = new DOMPrinter();
// Parse the XML document for parameters to the db call.
for (int j = 0; j < paramNodeList.getLength(); j++) {
// Get the node from the node list
Node paramNode = paramNodeList.item(j);
// Get name of the parameter.
String nameValue = xmlParseUtils.getAttributeValueFromNode(paramNode,
DBXmlConfig.NAME);
// Get type of the parameter.
String typeValue = xmlParseUtils.getAttributeValueFromNode(paramNode,
DBXmlConfig.TYPE);
// Get text value for the node
String textValue = "";
if (typeValue.equals(DBXmlConfig.STRING)) {
// Get child nodes
NodeList paramChildNodeList = paramNode.getChildNodes();
// If child node is not empty
if (paramChildNodeList.getLength() > 0) {
for (int k = 0; k < paramNodeList.getLength(); k++) {
textValue += domPrinter.printToString(paramChildNodeList.item(k),
"", "", false);
}
} else {
textValue = xmlParseUtils.getTextFromNode(paramNode);
}
} else {
textValue = xmlParseUtils.getTextFromNode(paramNode);
}
if (typeValue.equals(DBXmlConfig.STRING)) {
// Set the string
cstmt.setString(nameValue, textValue);
} else if (typeValue.equals(DBXmlConfig.INT)) {
// Convert string into int data type
int myInteger = Integer.valueOf(textValue).intValue() ;
// Set the int
cstmt.setInt(nameValue, myInteger);
} else if (typeValue.equals(DBXmlConfig.DATE)) {
// Convert string into date data type
Date myDate = Date.valueOf(textValue);
// Set the date
cstmt.setDate(nameValue, myDate);
}
} // end for each parameter
// Call the stored procedure to insert the data
try {
cstmt.execute();
if (writeData) {
ResultSet rs = null;
try {
rs = cstmt.getResultSet();
while (rs.next()) {
if (writeData) {
this.dataWriter.append(rs);
}
} // end while next record is available
}
finally {
try {
if (writeData) {
this.dataWriter.write(this.currentFilename, procedureNameValue);
}
if (rs != null) {
rs.close();
}
}
catch (SQLException sqle) {
super.msgEntry.setAppContext("callStoredProcedure()");
super.msgEntry.setDocInfo(currentFilename);
super.msgEntry.setMessageText("Unable to close result set.");
StringBuffer buffer = new StringBuffer(100);
// Multiple exceptions may be chained together. Get all information.
while (sqle != null) {
buffer.append( "Message: " + sqle.getMessage() );
buffer.append( " SQLState: " + sqle.getSQLState() );
buffer.append( " ErrorCode: " + sqle.getErrorCode() );
sqle = sqle.getNextException();
}
super.msgEntry.setError( new String(buffer) );
logger.logWarning(super.msgEntry);
}
}
}
}
catch (MysqlDataTruncation mdt) {
msgEntry.setAppContext("callStoredProcedure()");
msgEntry.setMessageText("Truncation error: Data is too long for column");
msgEntry.setDocInfo( domPrinter.simplePrintToString(modelDoc, "", "").substring(0, 350) );
msgEntry.setError(mdt.getMessage());
logger.logWarning(msgEntry);
throw(mdt);
}
finally {