aspose file tools*
The moose likes JDBC and the fly likes Unsupported Data Conversion - Due to returning primary Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Unsupported Data Conversion - Due to returning primary Key" Watch "Unsupported Data Conversion - Due to returning primary Key" New topic
Author

Unsupported Data Conversion - Due to returning primary Key

Fergus Red
Ranch Hand

Joined: Apr 25, 2002
Posts: 42
Hi, I've asked a similiar question to this forum already but could not get it solved.
What I said before was that I am getting a "Unsupported Data Conversion" on trying to insert a value in a database using a create() method in my EJB.
I've now realised that the error occurs in my container managed EJB because I am trying to return the primary key value for my new record inserted.
If I do not try to retrieve this value from my insert, my insert works fine.
I am using Microsoft SQL Server JDBC Driver. Before this I was using a JDBC-ODBC bridge and the error did not occur but since I moved to my SQL Server driver my error results.
My Stored Procedure called is as follows:
CREATE PROCEDURE spr_ins_ContactEvent
@cSession int,
@aSession int,
@interactiveItemKey int,
@accountKey int,
@treatKey int,
@methodOfContact char(6),
@promoCode char(6),
@direction char(1),
@contactDate datetime,
@contactEventKey int OUTPUT
AS
BEGIN
INSERT INTO contactEvent(cSession, aSession, interactiveItemKey, accountKey, treatKey, methodOfContact, promoCode, direction, contactDate)
VALUES (@cSession, @aSession, @interactiveItemKey, @accountKey, @treatKey, @methodOfContact, @promoCode, @direction, getDate())
SELECT @contactEventKey = MAX(contactEventKey) FROM contactEvent
END
GO
My XML insert method is as follows:
<env-entry>
<env-entry-name>ejipt.createSQL</env-entry-name>
<env-entry-value>{call spr_ins_ContactEvent (?,?,?,?,?,?,?,?,?,?)}</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>ejipt.createSQL.source</env-entry-name>
<env-entry-value>myjdbc</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>ejipt.createSQL.params</env-entry-name>
<env-entry-value>cSession,aSession,interactiveItemKey,accountKey,treatKey,methodOfContact,promoCode,direction,contactDate,contactEventKey UT</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>ejipt.createSQL.paramTypes</env-entry-name>
<env-entry-value>INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, CHAR, CHAR, CHAR, TIMESTAMP, INTEGER</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>ejipt.createSQL.fields</env-entry-name>
<env-entry-value>contactEventKey</env-entry-value>
</env-entry>

Can anyone see where my problem lies, or do you know if Microsoft SQL Server JDBC drivers always cause this problem?
Cheers in advance,
Fergus
Lilac Ezer
Greenhorn

Joined: Apr 08, 2003
Posts: 8
You said that when you take out the Output parameter, this works. It may be required with this JDBC driver to register the Output param as follows:
CallableStatement cs......
cs.registerOutParameter(10, Types.INTEGER);
 
wood burning stoves
 
subject: Unsupported Data Conversion - Due to returning primary Key