How to use the SQL Server JDBC bulk copy API
<p>I run into some issues trying to map my column metadata with SQL Server Bulk Copy API and <code>SQLServerBulkCSVFileRecord</code>. Just for test purposes I made a table consisting of only <code>nvarchar(500)</code> columns and add the metadata like this:</p>

<pre><code>fileRecord = new SQLServerBulkCSVFileRecord(csvPath, false);      

for(int i=1; i&lt;=colCount; i++) {
    fileRecord.addColumnMetadata(i, null, java.sql.Types.NVARCHAR, 500, 0);
} 
</code></pre>

<p>I  get the following stacktrace after using the Microsoft SQL bulk copy API with JDBC and I can't find any documentation on <code>SQLServerBulkCSVFileRecord</code>. I don't know what the parameters in <code>addColumnMetaData</code> stand for: I just assumed looking at <a href="https://msdn.microsoft.com/en-us/library/mt221490(v=sql.110).aspx" rel="nofollow noreferrer">this</a> example that the first parameter stands for column index and then obviously the third one for data-type, the fourth being byte count of the column(?).</p>

<pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: Unicode data is odd byte size for column 1. Should be even byte size.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
    at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:251)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:81)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:36)
    at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.doInsertBulk(SQLServerBulkCopy.java:1433)
    at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.access$200(SQLServerBulkCopy.java:41)
    at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy$1InsertBulk.doExecute(SQLServerBulkCopy.java:666)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793)
    at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.sendBulkLoadBCP(SQLServerBulkCopy.java:699)
    at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:1516)
    at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:616)
</code></pre>

<p>I read that blank lines, non CRLF line endings, encoding etc. could have an impact but I feel like I've exhausted those options.</p>

<p>Finally here's a little sample of my CSV file:</p>

<pre><code>column1|test|1|testtest|test3
column2|test|2|testt46426est|test346
column3|test|3|test4test|test3426234
</code></pre>