title: Pass Arraylst<Arraylist<String>> to MSSQL Stored procedure using JAVA?
body: <p>Here I am trying to pass List to stored procedure but getting the following error:</p>
  
  <blockquote>
    <p>Operand type clash: nvarchar is incompatible with UserType</p>
  </blockquote>
  
  <pre><code>//Stored Procedure
  ALTER PROCEDURE [dbo].[UserDetails]
  (
                  @OutId NVARCHAR(50) OUTPUT,
                  @Type NVARCHAR(50) Type,
                  ,@Preload UserType READONLY
  )
  AS
  </code></pre>
  
  <p>UserDefined datatype</p>
  
  <pre><code>CREATE TYPE [dbo].[UserType] AS TABLE(
                  [Id] [int] NULL,
                  [Name] [nvarchar](50) NULL,
                  [Company] [nvarchar](100) NULL,
                  [PNumber] [nvarchar](100) NULL,
                  [FClass] [nvarchar](100) NULL,
  )
  GO
  </code></pre>
  
  <p>JAVA Class</p>
  
  <pre><code>package Test;
  
  import java.sql.Array;
  import java.sql.CallableStatement;
  import java.sql.Clob;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.List;
  
  public class TestPreload {
  
                  public static void main(String[] args) {
                                  // TODO Auto-generated method stub
                                  ArrayList&lt;ArrayList&lt;String&gt;&gt; PreloadUser=new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
                                  ArrayList&lt;String&gt; Preload=new ArrayList&lt;String&gt;();
  
                                  Preload.add("1");
                                  Preload.add("Danny");
                                  Preload.add("123");
                                  Preload.add("123");
                                  Preload.add("N/A");
  
                                  PreloadUser.add(Preload);
  
                                  ArrayList&lt;String&gt; Preload2=new ArrayList&lt;String&gt;();
                                  Preload2.add("1");
                                  Preload2.add("Sam");
                                  Preload2.add("123");
                                  Preload2.add("123");
                                  Preload2.add("N/A");
  
                                  PreloadUser.add(Preload2);
  
                                  try {
                                                  DriverManager
                                                                                  .registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
                                                  Connection conn = DriverManager
                                                                                  .getConnection("jdbc:sqlserver://....");
                                                  CallableStatement stmt = conn
                                                                                  .prepareCall("{call UserDetails(?,?,?)}");
                                                  stmt.setString(2, "Test");
                                                  stmt.setString(3, PreloadUser.toString());
                                                  //stmt.setObject(3, PreloadUser.toString());
  
                                                  stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
                                                  stmt.execute();
                                                  System.out.println("OUTPUT : " + stmt.getString(1));
                                                                                                  } catch (SQLException e) {
                                                  // TODO Auto-generated catch block
                                                  e.printStackTrace();
                                  }
  
                  }
  
  }
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash:
    nvarchar is incompatible with UserType
          at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
          at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
          at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
          at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
          at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
          at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
          at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
          at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
          at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:320)
          at carma.TestInsurence.main(TestPreload.java:71)</p>
  </blockquote>