Skip to main content Microsoft Intelligent Data Platform Azure Arc Azure databases Power BI SQL Server 2025 SQL Server BI SQL Server 2022 SQL Server 2019 SQL Server 2017 SQL Server 2016 SQL Server 2005 - 2014 Downloads Community SQL End of Support Data Security - SQL Server Encryption SQL Server blog SQL Server and Azure SQL workshops Browse Microsoft Solutions Hub SQL Server Tech Community Azure Databases Tech Community Azure Synapse Analytics Tech Community Developer Find a partner Become a partner Partner resources Try SQL Server 2025 Microsoft Security Azure Dynamics 365 Microsoft 365 Microsoft Teams Windows 365 Microsoft AI Azure Space Mixed reality Microsoft HoloLens Microsoft Viva Quantum computing Sustainability Education Automotive Financial services Government Healthcare Manufacturing Retail Find a partner Become a partner Partner Network Microsoft Marketplace Software companies Blog Microsoft Advertising Developer Center Documentation Events Licensing Microsoft Learn Microsoft Research View Sitemap
·
2 min read

Preview the new JDBC 4.2 for SQL Server Driver

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.

English (United States)
Your Privacy Choices Opt-Out Icon Your Privacy Choices
Consumer Health Privacy Sitemap Contact Microsoft Privacy Manage cookies Terms of use Trademarks Safety & eco Recycling About our ads