Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 Java and Stored Proc with User Defined Table Type

Author  Topic 

sidestepper
Starting Member

3 Posts

Posted - 2012-08-09 : 21:32:09
Hello All,

In searching the web for this, it seems very few people have tried or think it may be impossible. I'm really hoping someone here may have an answer to it:

I'm newer to Java, but very experience in C# and have found most of what I need. I've figured out how to call a stored procedure(MS SQL 2008) with Java, but I cannot seem to find how I would pass a User Defined Table Type as an input:

The table type:

CREATE TYPE [dbo].[MyTableType] AS TABLE(
[id] [int] NOT NULL,
[year] [int] NOT NULL,
[day] [int] NOT NULL,
[month] [int] NOT NULL
)


The stored procedure:

CREATE PROCEDURE dbo.InsertSomeData
@myData MyTableType READONLY
AS
BEGIN
insert into PermanentDataTable ([id], [year], [day], [month])
select *
from @myData
END



Very simple and tested.... Now how do I call this from Java:

String sql = "exec dbo.InsertSomeData @myData=?";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setEscapeProcessing(true);
ps.setThatThingIWantToDo(1, arrayOfData); // <-- This part is where I'm stuck


Thanks in advance for any help
   

- Advertisement -