Preview the new JDBC 4.2 for SQL Server Driver

01

Jul

Preview the new JDBC 4.2 for SQL Server Driver

From Data Platform Blog:

Today we are pleased to announce availability of the Community Technology Preview (CTP) of the Microsoft JDBC 4.2 Driver for SQL Server! The driver provides robust data access to Microsoft SQL Server and Microsoft Azure SQL Database for Java-based applications.

The JDBC Driver for SQL Server is a Java Database Connectivity (JDBC) type 4 driver that implements full compliance with the JDBC specifications 4.1 and 4.2 and supports Java Development Kit (JDK) version 1.8. There are several additional enhancements available with the driver.  The updated XA Transaction feature includes new timeout options for automatic rollback of unprepared transactions. And, the new SQLServerBulkCopy class enables developers to quickly copy large amounts of data into tables or views in SQL Server and Azure SQL Database databases from other databases.

To use the SQLServerBulkCopy class, the basic flow is: connect to the source, then connect to the destination SQL Server or Azure SQL Database, create the SQLServerBulkCopy object and call WriteToServer.  The sample code below illustrates how the new class works:

// Obtain data from the source by connecting and loading it into a ResultSet

Connection sourceConnection = DriverManager.getConnection(connectionUrl);

 

String SQL = “SELECT * FROM SourceTable”;

Statement stmt = sourceConnection.createStatement();

ResultSet resultSet = stmt.executeQuery(SQL);

 

// Prepare for SQL Bulk Copy Operation

Connection destConnection = DriverManager.getConnection(connectionUrl);

 

// Default options are shown here

SQLServerBulkCopyOptions options = new SQLServerBulkCopyOptions();

options.setBatchSize(0);

options.setBulkCopyTimeout(30);

options.setCheckConstraints(false);

options.setFireTriggers(false);

options.setKeepIdentity(false);

options.setKeepNulls(false);

options.setTableLock(true);

options.setUseInternalTransaction(false);

 

SQLServerBulkCopy operation = new SQLServerBulkCopy(destConnection, options);

operation.setDestinationTableName(“DestinationTable”);

operation.addColumnMapping(1, 1);

operation.addColumnMapping(2, “test2”);

operation.addColumnMapping(“test3”, 3);

operation.addColumnMapping(“test4”, “test4”);

 

// Perform the copy

operation.writeToServer(resultSet);

 

// Finished

operation.close();

For more details about what is currently supported in the bulk copy feature preview, please refer to What’s New in the JDBC driver.

The JDBC driver is part of SQL Server and the Microsoft Data Platform’s wider interoperability program, with drivers for PHP 5.6, Node.jsJDBC, ODBC and ADO.NET already available. 

You can download the JDBC 4.2 driver preview hereWe invite you to explore the latest the Microsoft Data Platform has to offer via a trial of Microsoft Azure SQL Database or by trying the new SQL Server 2016 CTP. We look forward to hearing your feedback about the new driver. Let us know what you think on Microsoft Connect.


Source: Data Platform Insiders