百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

r2dbc-mssql

> 前端框架
开源

使用 TDS (表格数据流) 协议的 R2DBC 驱动程序 (适用于 Microsoft SQL Server)

195 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 TDS (表格数据流) 协议的 R2DBC 驱动程序 (适用于 Microsoft SQL Server)

Reactive Relational Database Connectivity Microsoft SQL Server Implementation

This project contains the Microsoft SQL Server implementation of the R2DBC SPI. This implementation is not intended to be used directly, but rather to be used as the backing implementation for a humane client library to delegate to

This driver provides the following features:

  • Complies with R2DBC 1.0
  • Login with username/password with temporary SSL encryption
  • Full SSL encryption support (for e.g. Azure usage).
  • Transaction Control
  • Simple execution of SQL batches (direct and cursored execution)
  • Execution of parametrized statements (direct and cursored execution)
  • Extensive type support (including TEXT, VARCHAR(MAX), IMAGE, VARBINARY(MAX) and national variants, see below for exceptions)
  • Execution of stored procedures

Next steps:

  • Add support for TVP and UDTs

Code of Conduct

This project is governed by the R2DBC Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to [email protected].

Getting Started

Here is a quick teaser of how to use R2DBC MSSQL in Java:

URL Connection Factory Discovery

java
ConnectionFactory connectionFactory = ConnectionFactories.get("r2dbc:mssql://:1433/");

Publisher connectionPublisher = connectionFactory.create();

When connecting through a tunnel or proxy, serverName can specify the logical SQL Server name independently from the physical connection endpoint:

java
ConnectionFactory connectionFactory = ConnectionFactories.get(
    "r2dbc:mssql://localhost:15433/?serverName=server.database.windows.net");

Programmatic Connection Factory Discovery

…

Supported ConnectionFactory Discovery Options

Option Description
ssl Whether to use transport-level encryption for the entire SQL server traffic.
driver Must be sqlserver.
host Server hostname to connect to.
port Server port to connect to. Defaults to 1433. (Optional)
username Login username.
password Login password.
database Initial database to select. Defaults to SQL Server user profile settings. (Optional)
applicationName Name of the application. Defaults to driver name and version. (Optional)
connectionId Connection Id for tracing purposes. Defaults to a random Id. (Optional)
connectionProvider Set the reactor.netty.resources.ConnectionProvider to be used when creating the connection. Defaults to ConnectionProvider.newConnection(). (Optional)
connectTimeout Connection Id for tracing purposes. Defaults to 30 seconds. (Optional)
hostNameInCertificate Expected hostname in SSL certificate. Supports wildcards (e.g. *.database.windows.net). (Optional)
lockWaitTimeout Lock wait timeout using SET LOCK_TIMEOUT …. (Optional)
preferCursoredExecution Whether to prefer cursors or direct execution for queries. Uses by default direct. Cursors require more round-trips but are more backpressure-friendly. Defaults to direct execution. Can be boolean or a Predicate accepting the SQL query. (Optional)
sendStringParametersAsUnicode Configure whether to send character data as unicode (NVARCHAR, NCHAR, NTEXT) or whether to use the database encoding, defaults to true. If disabled, CharSequence data is sent using the database-specific collation such as ASCII/MBCS instead of Unicode.
serverName Logical SQL Server name used as TLS SNI hostname and in the TDS login. Useful when host is a tunnel or proxy endpoint. Defaults to host, also the default for hostNameInCertificate. (Optional)
sslTunnel Enables SSL tunnel usage when using a SSL tunnel or SSL terminator in front of SQL Server. Accepts Function to customize the SSL tunnel settings. SSL tunneling is not related to SQL Server's built-in SSL support. (Optional)
sslContextBuilderCustomizer SSL Context customizer to configure SQL Server's built-in SSL support (Function) (Optional)
tcpKeepAlive Enable/disable TCP KeepAlive. Disabled by default. (Optional)
tcpNoDelay Enable/disable TCP NoDelay. Enabled by default. (Optional)
trustServerCertificate Fully trust the server certificate bypassing X.509 certificate validation. Disabled by default. (Optional)
trustStoreType Type of the TrustStore. Defaults to KeyStore.getDefaultType(). (Optional)
trustStore Path to the certificate TrustStore file. (Optional)
trustStorePassword Password used to check the integrity of the TrustStore data. (Optional)

Programmatic Configuration

java
MssqlConnectionConfiguration configuration = MssqlConnectionConfiguration.builder()
    .host("…")
    .serverName("…") // optional, defaults to host
    .username("…")
    .password("…")
    .database("…")
    .preferCursoredExecution(…)
    .build();

MssqlConnectionFactory factory = new MssqlConnectionFactory(configuration);

Mono connectionMono = factory.create();

Microsoft SQL Server uses named parameters that are prefixed with @. The following SQL statement makes use of parameters:

sql
INSERT INTO person (id, first_name, last_name) VALUES(@id, @firstname, @lastname)

Parameters are referenced without the @ prefix when binding these:

java
connection.createStatement("INSERT INTO person (id, first_name, last_name) VALUES(@id, @firstname, @lastname)")
            .bind("id", 1)
            .bind("firstname", "Walter")
            .bind("lastname", "White")
            .execute()

Binding also allows positional index (zero-based) references. The parameter index is derived from the parameter discovery order when parsing the query.

Maven configuration

Artifacts can be found on Maven Central.

xml

  io.r2dbc
  r2dbc-mssql
  ${version}

If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.

xml

  io.r2dbc
  r2dbc-mssql
  ${version}.BUILD-SNAPSHOT

  central-portal-snapshots
  Central Portal Snapshots
  https://central.sonatype.com/repository/maven-snapshots/

Transaction Definitions

SQL Server supports additional options when starting a transaction. In particular, the following options can be specified:

  • Isolation Level (isolationLevel) (reset after the transaction to previous value)
  • Transaction Name (name)
  • Transaction Log Mark (mark)
  • Lock Wait Timeout (lockWaitTimeout) (reset after the transaction to -1)

These options can be specified upon transaction begin to start the transaction and apply options in a single command round

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaazure-sql-servermicrosoft-sql-servernon-blockingr2dbc

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架