int bytesRead = 0;
int bufferSize = 0;
String theQuery = null;
Writer out = null;
StringReader in = null;
CLOB clob = null;
try {
logger.debug9("calling " + SOSClassUtil.getMethodName());
if (connection == null)
throw new Exception(
"sorry, there is no successful connection established."
+ " may be the connect method is not called");
if (SOSString.isEmpty(tableName))
throw new NullPointerException("tableName is null.");
if (SOSString.isEmpty(columnName))
throw new NullPointerException("columnName is null.");
if (SOSString.isEmpty(data))
throw new Exception("data has null value.");
query = new StringBuffer("UPDATE ");
if (tableNameUpperCase)
query.append(tableName.toUpperCase());
else
query.append(tableName);
if (fieldNameUpperCase) {
query.append(" SET \"");
query.append(columnName.toUpperCase());
query.append("\" = empty_clob() ");
} else {
query.append(" SET ");
query.append(columnName);
query.append(" = empty_clob() ");
}
if (!SOSString.isEmpty(condition))
condition = " WHERE " + condition;
else
condition = "";
query.append(condition);
theQuery = this.normalizeStatement(query.toString(), replacement);
logger.debug6(SOSClassUtil.getMethodName() + ": " + theQuery);
stmt = connection.createStatement();
stmt.executeUpdate(theQuery);
try {
stmt.close();
stmt = null;
} catch (Exception e) {
throw new Exception(" an error occurred closing the statement: "
+ e);
}
stmt = connection.createStatement();
if (fieldNameUpperCase) {
query = new StringBuffer("SELECT \"");
query.append(columnName.toUpperCase());
query.append("\" FROM ");
} else {
query = new StringBuffer("SELECT ");
query.append(columnName);
query.append(" FROM ");
}
if (tableNameUpperCase)
query.append(tableName.toUpperCase());
else
query.append(tableName);
query.append(" ");
query.append(condition);
query.append(" for update nowait");
theQuery = this.normalizeStatement(query.toString(), replacement);
logger.debug6(SOSClassUtil.getMethodName() + ": " + theQuery);
rs = stmt.executeQuery(theQuery);
if (rs.next()) clob = (CLOB) rs.getClob(1);
bufferSize = clob.getBufferSize();
char[] buffer = new char[bufferSize];
out = clob.getCharacterOutputStream();
in = new StringReader(data);
while ((bytesRead = in.read(buffer, 0, bufferSize)) != -1) {
out.write(buffer, 0, bytesRead);
totalBytesWritten += bytesRead;
}