It's not a secret anymore!
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "Unsupported Data Conversion - Due to returning primary Key" Watch "Unsupported Data Conversion - Due to returning primary Key" New topic

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
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
My XML insert method is as follows:
<env-entry-value>{call spr_ins_ContactEvent (?,?,?,?,?,?,?,?,?,?)}</env-entry-value>
<env-entry-value>cSession,aSession,interactiveItemKey,accountKey,treatKey,methodOfContact,promoCode,direction,contactDate,contactEventKey UT</env-entry-value>

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

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);
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Unsupported Data Conversion - Due to returning primary Key
It's not a secret anymore!