2

I'm trying to execute a stored procedure like follows:

CallableStatement cs = this.con.prepareCall("{call getDeliveryConfirmations(?)}");
cs.setString(1, "545A6F33-A22A-47A6-AF97-0D952F2D80D7");
Resultset rs = cs.executeQuery();

As you can see I'm setting a Guid/UniqueIdentifier in the callable statement as a parameter before executing... But as you also can make out is that I use the method 'setString' on the callableStatement object and as a result I'm getting this error:

com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting from a character string to uniqueidentifier.

I'd imagine that if there was a method like 'setGuid' or something for the callablestatement object that I won't have this problem... Anyone know of a workaround etc?

Edit:

Code for the stored procedure 'getDeliveryConfirmations'

USE [VodacomXml2Sms]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
BEGIN
SET NOCOUNT ON;
select * from OutgoingDeliveryConfirmations
where smsGuid = @selectedGuid
END
  • Could you post the code for `getDeliveryConfirmations` as well (at least the declaration)? – Thomas Mueller May 07 '12 at 08:17
  • There you go... Obviously @selectedGuid is the parameter I'm sending through to the stored proc in the java code –  May 07 '12 at 08:29

1 Answers1

0

I fear if your Guid and uniqueidentifier have data type or size mismatch.
Check if this works for you.

Community
  • 1
  • 1
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82
  • What happens when you declare a variable meant for a guid like this: declare (at)guidParameter varchar; instead of declare (at)guidParameter nvarchar(36); ? Could this potentially be the reason for the error? –  May 07 '12 at 08:34
  • @DeanGrobler - I am not sure about that, but can you please check your call with `cs.setNString(..)` – Ravinder Reddy May 07 '12 at 08:50