Hello,
in my application, I'm inserting a record into a database on one page and updating it
on another. I'm using Java to insert the records, by the way. My problem is that
when
I try to insert this record again on the next page, the database won't let me do it
because of the primary key. I was told that I can overcome this situation by using
the
function UPDATE instead of the INSERT in my onWebEvent, (I used INSERT on the
previous page). However, the code that I have for the Update buttong onWebEvent
doesn't work and I can't figure out the reason. Does anyone have any suggestions?
The following is the code:
//[[SPIDER_EVENT<btUpdate_onWebEvent>
public int btUpdate_onWebEvent(CSpWebEvent event)
{
int command = PROCEED;
CSpDBResult resultSet = null;
CSpDBResultStatus resultStatus = null;
Integer year = new Integer
(getDisplayFieldValue("dfYear").stringValue().trim());
Integer month = new Integer
(getDisplayFieldValue("dfMonth").stringValue().trim());
Integer day = new Integer
(getDisplayFieldValue("dfDay").stringValue().trim());
String date = new
String(year.toString()+month.toString()+day.toString());
CSpider.putUserSessionObject("sesDate", (CSpValue) new
CSpString(date));
String high52 = getDisplayFieldValue("df52High").stringValue().trim();
CSpider.putUserSessionObject("sesHigh52", (CSpValue) new
CSpString(high52));
String low52 = getDisplayFieldValue("df52Low").stringValue().trim();
CSpider.putUserSessionObject("ses52Low", (CSpValue) new
CSpString(low52));
String dataAsOf =
getDisplayFieldValue("dfDataAsOf").stringValue().trim();
CSpider.putUserSessionObject("sesDataAsOf", (CSpValue) new
CSpString(dataAsOf));
String sql = "UPDATE dataAndStockPrices ";
sql = sql + "VALUES (";
sql = sql + "'" + date + "'";
sql = sql + ", " + day.intValue();
sql = sql + ", " + month.intValue();
sql = sql + ", " + year.intValue();
sql = sql + ", '" + high52 + "'";
sql = sql + ", '" + low52 + "'";
sql = sql + ", '" + dataAsOf + "'";
sql = sql + ")";
resultSet = CSpDataObject.executeImmediate("dsDailyNews", sql);
resultStatus = resultSet.getResultStatus();
if (resultStatus.getVendorErrorCode1() == resultStatus.SUCCESS)
{
CSpCommonPage pgViewData = CSpider.getCommonPage("pgViewData");
pgViewData.load(false);
return(PROCEED);
}
else
{
CSpCommonPage pgError = CSpider.getCommonPage("pgError");
pgError.setDisplayFieldValue("stMessage", new CSpString("This
is an error associated
w/ the 'DataObjectExecuteImmediate' method - SQL Error
("+resultStatus.getVendorErrorCode1()+"):
"+resultStatus.getVendorErrorMessage1()+". Please contact the Internet
Services
Group for help."));
pgError.load(false);
return(STOP);
}
}
//]]SPIDER_EVENT<btUpdate_onWebEvent>
I would really appreciate your help.
Thanks in advance,
Rimma
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]