我尝试使用MS JDBC驱动程序连接到Azure sql:
import java.sql.*;
public class Examplesqljdbc {
public static void main(String[] args) {
// Setting.
String connectionUrl = "jdbc:sqlserver://SERVER.database.windows.net:1433;database=DATABASE;encrypt=true;trustServerCertificate=true;";
String user = "USER@SERVER";
String pass = "PASSWORD";
// Declare the JDBC object.
Connection conn = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.sqlServerDriver");
conn = DriverManager.getConnection(connectionUrl, user, pass);
}
catch (Exception e) {
e.printstacktrace();
}
}
}
但我得到:
com.microsoft.sqlserver.jdbc.sqlServerException: The driver Could not establish a secure connection to sql Server by using Secure Sockets Layer (SSL) encryption. Error: "broken pipe ClientConnectionId:742ba7b5-43bb-441b-8e8d-bbb9dc5fa8ce".
at com.microsoft.sqlserver.jdbc.sqlServerConnection.terminate(sqlServerConnection.java:2226)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1756)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.connectHelper(sqlServerConnection.java:1803)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.login(sqlServerConnection.java:1454)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.connectInternal(sqlServerConnection.java:1285)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.connect(sqlServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.sqlServerDriver.connect(sqlServerDriver.java:1131)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at run.Examplesqljdbc.main(Examplesqljdbc.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
有趣的是,我可以使用Navicat从同一台计算机连接到数据库.因此,问题不应该在防火墙的设置中.
元数据:
>服务器:Azure V12
>驱动程序:6.0(sqljdbc42.jar)
> JRE:1.8.0_72-b15(来自Oracle)
> _JAVA_OPTIONS:-Djsse.enableCBCProtection = false
> security.provider.1:sun.security.provider.Sun
> OS:OS X 10.11.5
如何从Java连接到Azure sql?
编辑:
如果我在OS X上使用javac 1.8.0_92从Peter Pan编译代码并在OS X上使用java 1.8.0_92执行字节码,则错误不会消失.
编辑2:
当我使用-Djavax.net.debug = ssl:handshake:verbose来描述SSL连接细节时:
trigger seeding of SecureRandom
done seeding SecureRandom
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
Allow unsafe renegotiation: false
Allow legacy hello messages: true
Is initial handshake: true
Is secure renegotiation: false
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1.1
%% No cached client session
*** ClientHello, TLSv1.2
RandomCookie: GMT: 1466081162 bytes = { 238, 135, 254, 162, 132, 164, 75, 240, 96, 107, 17, 103, 60, 109, 229, 149, 31, 110, 218, 87, 49, 29, 121, 114, 115, 6, 44, 32 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, secp192k1, sect193r1, sect193r2, secp224k1, sect239k1, secp256k1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA224withECDSA, SHA224withRSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
Extension server_name, server_name: [type=host_name (0), value=hlt3qa7607.database.windows.net]
***
main, WRITE: TLSv1.2 Handshake, length = 233
main, called close()
main, called closeInternal(true)
main, SEND TLSv1.2 ALERT: warning, description = close_notify
main, WRITE: TLSv1.2 Alert, length = 2
main, called closeSocket(true)
main, waiting for close_notify or alert: state 5
main, received EOFException: ignored
main, called closeInternal(false)
main, close invoked again; state = 5
main, handling exception: java.io.IOException: sql Server did not return a response. The connection has been closed. ClientConnectionId:1eb03958-1566-4844-b842-e020f0c36121
main, called closeSocket()
com.microsoft.sqlserver.jdbc.sqlServerException: The driver Could not establish a secure connection to sql Server by using Secure Sockets Layer (SSL) encryption. Error: "sql Server did not return a response. The connection has been closed. ClientConnectionId:1eb03958-1566-4844-b842-e020f0c36121"....
编辑3:
设置驱动程序后记录所有:
Jun 17, 2016 9:26:37 AM com.microsoft.sqlserver.jdbc.sqlServerDriver:1 connect
FINER: ENTRY Arguments not traced.
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.Util parseUrl
FINE: Property:serverName Value:hlt3qa7607.database.windows.net
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.Util parseUrl
FINE: Property:portNumber Value:1433
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.Util parseUrl
FINE: Property:databaseName Value:DATABASE
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.Util parseUrl
FINE: Property:encrypt Value:true
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.Util parseUrl
FINE: Property:trustServerCertificate Value:true
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection <init>
FINE: ConnectionID:1 created by (sqlServerDriver:1)
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection login
FINER: ConnectionID:1 Start time: 1466148398058 Time out time: 1466148413058 Timeout Unit Interval: 1200
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection login
FINE: ConnectionID:1 This attempt server name: hlt3qa7607.database.windows.net port: 1433 InstanceName: null useParallel: false
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection login
FINE: ConnectionID:1 This attempt endtime: 1466148399258
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection login
FINE: ConnectionID:1 This attempt No: 0
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection connectHelper
FINE: ConnectionID:1 Connecting with server: hlt3qa7607.database.windows.net port: 1433 Timeout slice: 1194 Timeout Full: 15
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel open
FINER: TDSChannel (ConnectionID:1): opening TCP socket...
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c Requesting encryption level:ON
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c ActivityId 866c0053-25be-4eb2-90c7-a40b5b0535a4-1
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel logPacket
FInesT: /192.168.1.186:63328 SPID:0 ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c Prelogin request ...
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel logPacket
FInesT: /192.168.1.186:63328 SPID:0 ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c Prelogin response
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection Prelogin
FINE: ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c Server returned major version:12
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c Negotiated encryption level:ON
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.sqlServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c Ignoring prelogin response option:5
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) Enabling SSL...
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) SSL handshake will trust any certificate
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FInesT: TDSChannel (ConnectionID:1) Getting TLS or better SSL context
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FInesT: TDSChannel (ConnectionID:1) Initializing SSL context
Jun 17, 2016 9:26:38 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FInesT: TDSChannel (ConnectionID:1) Creating SSL socket
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxySocket getInputStream
FInesT: TDSChannel (ConnectionID:1) (ProxySocket): Getting input stream
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxySocket getoutputStream
FInesT: TDSChannel (ConnectionID:1) (ProxySocket): Getting output stream
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) Starting SSL handshake
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream writeInternal
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream@13c78c0b Writing 238 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeOutputStream writeInternal
FInesT: TDSChannel (ConnectionID:1) (SSLHandshakeOutputStream): Starting new TDS packet...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSWriter writeBytes
FInesT: TDSWriter@41629346 (ConnectionID:1) Writing 8 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeOutputStream writeInternal
FInesT: TDSChannel (ConnectionID:1) (SSLHandshakeOutputStream): Writing 238 bytes...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSWriter writeBytes
FInesT: TDSWriter@41629346 (ConnectionID:1) Writing 238 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream flush
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream@13c78c0b Flushing
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeOutputStream flush
FInesT: TDSChannel (ConnectionID:1) (SSLHandshakeOutputStream): Ignored a request to flush the stream
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream readInternal
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream@12843fce Reading 5 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream readInternal
FInesT: TDSChannel (ConnectionID:1) (SSLHandshakeInputStream): Reading 5 bytes...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream ensureSSLPayload
FInesT: TDSChannel (ConnectionID:1) (SSLHandshakeInputStream): No handshake response bytes available. Flushing SSL handshake output stream.
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeOutputStream endMessage
FInesT: TDSChannel (ConnectionID:1) (SSLHandshakeOutputStream): Finishing TDS message
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSWriter endMessage
FInesT: TDSWriter@41629346 (ConnectionID:1) Finishing TDS message
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel logPacket
FInesT: /0:0:0:0:0:0:c0a8:1ba:63328 SPID:0 TDSWriter@41629346 (ConnectionID:1) sending packet (246 bytes)
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel write
FINER: TDSChannel (ConnectionID:1) write Failed:broken pipe
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerException logException
FINE: *** sqlException:ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c com.microsoft.sqlserver.jdbc.sqlServerException: broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerException logException
FINE: com.microsoft.sqlserver.jdbc.sqlServerConnection.terminate(sqlServerConnection.java:2226)com.microsoft.sqlserver.jdbc.sqlServerConnection.terminate(sqlServerConnection.java:2210)com.microsoft.sqlserver.jdbc.TDSChannel.write(IOBuffer.java:1894)com.microsoft.sqlserver.jdbc.TDSWriter.flush(IOBuffer.java:4285)com.microsoft.sqlserver.jdbc.TDSWriter.writePacket(IOBuffer.java:4186)com.microsoft.sqlserver.jdbc.TDSWriter.endMessage(IOBuffer.java:3192)com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeOutputStream.endMessage(IOBuffer.java:824)com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:687)com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:762)com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:754)com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:949)com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:937)sun.security.ssl.InputRecord.readFully(InputRecord.java:465)sun.security.ssl.InputRecord.read(InputRecord.java:503)sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1682)com.microsoft.sqlserver.jdbc.sqlServerConnection.connectHelper(sqlServerConnection.java:1803)com.microsoft.sqlserver.jdbc.sqlServerConnection.login(sqlServerConnection.java:1454)com.microsoft.sqlserver.jdbc.sqlServerConnection.connectInternal(sqlServerConnection.java:1285)com.microsoft.sqlserver.jdbc.sqlServerConnection.connect(sqlServerConnection.java:700)com.microsoft.sqlserver.jdbc.sqlServerDriver.connect(sqlServerDriver.java:1131)java.sql.DriverManager.getConnection(DriverManager.java:664)java.sql.DriverManager.getConnection(DriverManager.java:247)Examplesqljdbc.main(Examplesqljdbc.java:44)
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerConnection:1 close
FINER: ENTRY
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FINER: TDSChannel (ConnectionID:1) disabling SSL...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FInesT: TDSChannel (ConnectionID:1) Rewiring proxy streams for SSL socket close
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FINER: TDSChannel (ConnectionID:1) Closing SSL socket
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream writeInternal
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream@13c78c0b Writing 7 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream flush
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyOutputStream@13c78c0b Flushing
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream readInternal
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream@12843fce Reading 5 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream readInternal
FInesT: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream@12843fce Read -1 bytes
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FINER: TDSChannel (ConnectionID:1) SSL disabled
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FInesT: TDSChannel (ConnectionID:1): Closing inputStream...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FInesT: TDSChannel (ConnectionID:1): Closing outputStream...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FINER: TDSChannel (ConnectionID:1): Closing TCP socket...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerConnection:1 close
FINER: RETURN
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream ensureSSLPayload
FINER: TDSChannel (ConnectionID:1) (SSLHandshakeInputStream): Ending TDS message threw exception:broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream readInternal
FINER: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream@12843fce broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream readInternal
FINER: com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream@12843fce Reading bytes threw exception:broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel$ProxySocket close
FINER: TDSChannel (ConnectionID:1) (ProxySocket): Ignoring close
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c
java.io.IOException: broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:692)
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:762)
at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:754)
at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:949)
at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:937)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1682)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.connectHelper(sqlServerConnection.java:1803)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.login(sqlServerConnection.java:1454)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.connectInternal(sqlServerConnection.java:1285)
at com.microsoft.sqlserver.jdbc.sqlServerConnection.connect(sqlServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.sqlServerDriver.connect(sqlServerDriver.java:1131)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Examplesqljdbc.main(Examplesqljdbc.java:44)
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: java.security path: /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/security
Security providers: [SUN version 1.8, SunRsaSign version 1.8, SunEC version 1.8, SunjsSE version 1.8, SunJCE version 1.8, Sunjgss version 1.8, SunSASL version 1.8, XMLDSig version 1.8, SunPCSC version 1.8, Apple version 1.8]
SSLContext provider info: Sun JSSE provider(PKCS12, SunX509/PKIX key/trust factories, SSLv3/TLSv1/TLSv1.1/TLSv1.2)
SSLContext provider services:
[SunjsSE: KeyFactory.RSA -> sun.security.rsa.RSAKeyFactory
aliases: [1.2.840.113549.1.1, OID.1.2.840.113549.1.1]
, SunjsSE: KeyPairGenerator.RSA -> sun.security.rsa.RSAKeyPairGenerator
aliases: [1.2.840.113549.1.1, OID.1.2.840.113549.1.1]
, SunjsSE: Signature.MD2withRSA -> sun.security.rsa.RSASignature$MD2withRSA
aliases: [1.2.840.113549.1.1.2, OID.1.2.840.113549.1.1.2]
, SunjsSE: Signature.MD5withRSA -> sun.security.rsa.RSASignature$MD5withRSA
aliases: [1.2.840.113549.1.1.4, OID.1.2.840.113549.1.1.4]
, SunjsSE: Signature.SHA1withRSA -> sun.security.rsa.RSASignature$SHA1withRSA
aliases: [1.2.840.113549.1.1.5, OID.1.2.840.113549.1.1.5, 1.3.14.3.2.29, OID.1.3.14.3.2.29]
, SunjsSE: Signature.MD5andSHA1withRSA -> sun.security.ssl.RSASignature
, SunjsSE: KeyManagerFactory.SunX509 -> sun.security.ssl.KeyManagerFactoryImpl$SunX509
, SunjsSE: KeyManagerFactory.NewSunX509 -> sun.security.ssl.KeyManagerFactoryImpl$X509
aliases: [PKIX]
, SunjsSE: TrustManagerFactory.SunX509 -> sun.security.ssl.TrustManagerFactoryImpl$SimpleFactory
, SunjsSE: TrustManagerFactory.PKIX -> sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory
aliases: [SunPKIX, X509, X.509]
, SunjsSE: SSLContext.TLSv1 -> sun.security.ssl.SSLContextImpl$TLS10Context
aliases: [SSLv3]
, SunjsSE: SSLContext.TLSv1.1 -> sun.security.ssl.SSLContextImpl$TLS11Context
, SunjsSE: SSLContext.TLSv1.2 -> sun.security.ssl.SSLContextImpl$TLS12Context
, SunjsSE: SSLContext.TLS -> sun.security.ssl.SSLContextImpl$TLSContext
aliases: [SSL]
, SunjsSE: SSLContext.Default -> sun.security.ssl.SSLContextImpl$DefaultSSLContext
, SunjsSE: KeyStore.PKCS12 -> sun.security.pkcs12.PKCS12KeyStore
]
java.ext.dirs: /Users/jan/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerException logException
FINE: *** sqlException:ConnectionID:1 ClientConnectionId: 1a3032c8-493d-4f99-8641-d0f02211d82c com.microsoft.sqlserver.jdbc.sqlServerException: The driver Could not establish a secure connection to sql Server by using Secure Sockets Layer (SSL) encryption. Error: "broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c". The driver Could not establish a secure connection to sql Server by using Secure Sockets Layer (SSL) encryption. Error: "broken pipe ClientConnectionId:1a3032c8-493d-4f99-8641-d0f02211d82c".
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerException logException
FINE: com.microsoft.sqlserver.jdbc.sqlServerConnection.terminate(sqlServerConnection.java:2226)com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1756)com.microsoft.sqlserver.jdbc.sqlServerConnection.connectHelper(sqlServerConnection.java:1803)com.microsoft.sqlserver.jdbc.sqlServerConnection.login(sqlServerConnection.java:1454)com.microsoft.sqlserver.jdbc.sqlServerConnection.connectInternal(sqlServerConnection.java:1285)com.microsoft.sqlserver.jdbc.sqlServerConnection.connect(sqlServerConnection.java:700)com.microsoft.sqlserver.jdbc.sqlServerDriver.connect(sqlServerDriver.java:1131)java.sql.DriverManager.getConnection(DriverManager.java:664)java.sql.DriverManager.getConnection(DriverManager.java:247)Examplesqljdbc.main(Examplesqljdbc.java:44)
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerConnection:1 close
FINER: ENTRY
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FInesT: TDSChannel (ConnectionID:1): Closing inputStream...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FInesT: TDSChannel (ConnectionID:1): Closing outputStream...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FINER: TDSChannel (ConnectionID:1): Closing TCP socket...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerConnection:1 close
FINER: RETURN
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerConnection:1 close
FINER: ENTRY
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FInesT: TDSChannel (ConnectionID:1): Closing inputStream...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FInesT: TDSChannel (ConnectionID:1): Closing outputStream...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.TDSChannel close
FINER: TDSChannel (ConnectionID:1): Closing TCP socket...
Jun 17, 2016 9:26:43 AM com.microsoft.sqlserver.jdbc.sqlServerConnection:1 close
FINER: RETURN
解决方法:
这些步骤解决了这个问题:
>开放式终端(/ Applications / Utilities / Terminal)
>运行scutil –get HostName(区分大小写!)
>如果未设置主机名或包含.local,请运行sudo scutil –set HostName“newname”
>再次尝试JDBC Azure sql连接 – 主机名更改立即生效
资料来源:https://youtrack.jetbrains.com/issue/JRE-221#comment=27-1826316