cancel
Showing results for 
Search instead for 
Did you mean: 

How to store/manipulate Date and long text fields with Dictionary project

Former Member
0 Kudos

I am able to save string values into my backend (SQL Server) database in my web dynpro project but I am getting errors dealing with my date string and my long text (comments) field.

I want to figure out both how I need to define the fields in the dictionary project, how to define the context variables in web dynpro, and how to code the statements to pull the values out of the context and into fields I can use in my SQL insert.

Currently I have the date defined in the dictionary project as "date" and the comments as a 256-character string.

In the web dynpro context I have the date field defined as "date" and the comments field defined as "string". Should I define a 256-character string type and use that as field type??

In the code I am using the following to get the values:

String s9 = (String) wdContext.nodeReceipt().getElementAt(wdContext.nodeReceipt().getLeadSelection()).getAttributeValue("Comments");

String s5 = (String) wdContext.nodeReceipt().getElementAt(wdContext.nodeReceipt().getLeadSelection()).getAttributeValue("DateReceived");

SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");

try {

Date dt = sdf.parse(s5);

} catch (Exception e) {

e.printStackTrace();

}

I then try to insert all of my values with the following code:

InitialContext ctx = new InitialContext();

javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/SAP/BC_JMS");

java.sql.Connection con = ds.getConnection();

java.sql.Statement stmt = con.createStatement();

stmt.executeUpdate("insert into AVD_GEN_REC(VENDOR,DATE_RECEIVED,TOTAL_PIECES,LOGGED_BY," +

"ADDRESSED_TO,BLDG_NO,CARRIER,TRACKING_NO, COMMENTS) values('s1','s5','s2','s6','s3','s7','s4','s8','s9')");

} catch (Exception e) {

wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Exception "+e.getMessage());

}

Any help/ideas would be appreciated...

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

The comment error seems to have resolved itself but I still get an error with the date field:

Exception The SQL statement "INSERT INTO "AVD_GEN_REC" ("VENDOR","DATE_RECEIVED","TOTAL_PIECES","LOGGED_BY","ADDRESSED_TO","BLDG_NO","CARRIER","TRACKING_NO","COMMENTS") VALUES ('s1','d5','s2','s6','s3','s7','s4','s8','s9')" contains the semantics error[s]: type check error: new value (element number 2) is not assignable to column "DATE_RECEIVED"

The DATE_RECEIVED is defined in the data dictionary as "date", the context variable "DateReceived" is also a "date", and the statement to pull d5 is being stored to a "Date". Is there a difference between the "Date" and "date"?

Date d5 = wdContext.currentReceiptElement().getDateReceived();

lajitha_menon
Contributor
0 Kudos

Hi,

Hi,

Try this in the first part to get the values.

String s9= wdContext.currentReceiptElement().getComments();

Date s5 = wdContext.currentReceiptElement().getDateReceived();

In your code, you are passing the string s5 to insert, but the parsed value is in dt.

Try and let me know if it worked,

Regards,

LM

Former Member
0 Kudos

Sorry- I did have "dt" in there in place of "s5" a while back but the "dt" generated an SQL error so I put the "s5" in.

I will try what you suggest to pull in the values. My dev server is down at the moment so I may not know for a while if it works or not but will let you know as soon as I'm able to test it.