Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class SqlServer
- Object
- ServerSession
- SqlServer
A SQL Server client speaking TDS 7.4, the Tabular Data Stream, written from Microsoft’s published MS-TDS specification. SQL Server 2017 and later, and Azure SQL.
SqlServer db = SqlServer.connect("db.internal", 1433, "app", "user", "secret",
"require", null, 10000, 0);
List rows = db.query("SELECT id, name FROM users WHERE id = @p1", new Object[] {7L});Statements
A statement with parameters is an RPC call to sp_executesql, with the
parameters named @p1, @p2 and so on and typed from the Java values. One
without is a plain batch. Values never travel inside the statement text.
Encryption
The TLS handshake is carried inside PRELOGIN packets, which is how every
SQL Server before TDS 8.0 negotiates it. The client asks for the whole
session to be encrypted, never the login alone, for every sslmode but
disable. A login sends the password scrambled, not hashed, so a server
without TLS is refused unless sslmode=disable says the plaintext is
deliberate.
sslmode=strict is TDS 8.0: TLS first, before any TDS byte, with PRELOGIN
and the login inside it, the certificate verified for the host and ALPN
tds/8.0 offered. It is what a server or Azure SQL set to strict encryption
requires. SQL Server on Linux serves it from 2025; 2022 on Linux refuses
every strict connection (error 17821) whatever its certificate.
Sign-in
A SQL login by name and password, or a Windows account over NTLMv2 when the
user is written DOMAIN\\user. Kerberos and Microsoft Entra ID are not
implemented.
Values
Integers and bits arrive as Long, floats as Double, binary as
byte[], and everything else as a String in the form the other engines
use: decimals and money as digits, dates and times as
yyyy-MM-dd HH:mm:ss.fff.
Fields
public static final ServerSession.Connector CONNECTOR | Opens SqlServer sessions; naming this constant is what puts the engine in an application. |
Methods
Inherited nested types
Inherited methods
Field details
CONNECTOR
public static final ServerSession.Connector CONNECTORServerSession.Connector.Method details
dialect
public Dialect dialect()ownsTransactionControl
public boolean ownsTransactionControl()connect
public static SqlServer connect(String host, int port, String database, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis)
throws IOExceptionOpens a session.
sslMode is what the other engines take: require (and verify-full)
demand TLS to a certificate that verifies for host, verify-ca a
chain to caFile without the name, prefer uses TLS and fails when the
server has none, since a login cannot be protected without it, and
disable is plaintext, deliberately. strict is SQL Server’s own: TDS
8.0, TLS before the first packet, verified as require is.
A user written DOMAIN\\user signs in as that Windows account over
NTLMv2; any other is a SQL login.
An Azure SQL gateway that answers the login with a redirect is followed, once.
Throws
execute
public int execute(String sql, Object[] params)
throws IOExceptionReturns
Throws
query
public List query(String sql, Object[] params)
throws IOExceptionMap of column name
to value in projection order. A statement that produces several result
sets answers with the first.Throws
lastInsertId
public long lastInsertId()begin
public void begin()
throws IOExceptionThrows
beginReadOnly
public void beginReadOnly()
throws IOExceptionbegin.Throws
begin
public void begin(boolean readOnly, TransactionIsolation isolation)
throws IOExceptionThrows
commit
public void commit()
throws IOExceptionThrows
rollback
public void rollback()
throws IOExceptionThrows
savepoint
public void savepoint(String verb, String name)
throws IOExceptionThrows
close
public void close()isClosed
public boolean isClosed()