我正在尝试SQL Server 2008
使用sqljdbc4.jar
Eclipse 连接并可以成功连接。
但是,当我将代码导出为 JAR 并尝试使用命令提示符运行它时,出现错误:
D:\Eclipse\TestDBJar>java -Djava.ext.dirs=lib -jar TestDB.jar Apr 5, 2013 11:17:17 AM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL INFO: java.security path: C: \Program Files\Java\jre6\lib\security 安全提供程序:[SUN 1.6 版、SunRsaSign 1.5 版、SunJSSE 1.6 版、SunJGSS 1.0 版、SunSASL 1.5 版、XMLDSig 1.0 版、SunPCSC 1.6 版] SSLContext 提供程序信息: Sun JSSE 提供者(PKCS12、SunX509 密钥/信任工厂、SSLv3、TLSv1) SSLContext 提供者服务:[SunJSSE:KeyFactory.RSA -> sun.security.rsa.RSAKeyFactory 别名:[1.2.840.113549.1.1,OID.1.2.840.113549。 1.1],SunJSSE:KeyPairGenerator.RSA -> sun.security.rsa.RSAKeyPairGenerator
别名:[1.2.840.113549.1.1,OID.1.2.840.113549.1.1],SunJSSE:Signature.MD2withRSA -> sun.security.rsa.RSASignature$MD2withRSA
别名:[1.2.840.113549.1.1.2,OID.1.2.840.113549 .1.1.2] , SunJSSE: Signature.MD5withRSA -> sun.security.rsa.RSASignature$MD5withRSA
别名: [1.2.840.113549.1.1.4, OID.1.2.840.113549.1.1.4] , SunJSSE: Signature.SHA1withRSA - > sun.security.rsa.RSASignature$SHA1withRSA
别名:[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 -> com.sun.net .ssl.internal.ssl.RSASignat ure , SunJSSE: KeyManagerFactory.SunX509 -> com.sun.net.ssl.internal.ssl.KeyManagerF actoryImpl$SunX509 , SunJSSE: KeyManagerFactory.NewSunX509 -> com.sun.net.ssl.internal .ssl.KeyManagerFactoryImpl$X509,SunJSSE:TrustManagerFactory.SunX509 -> com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl$SimpleFactory,SunJSSE:TrustManagerFactory.PKIX -> com.sun.net.ssl.internal.ssl .TrustManager FactoryImpl$PKIXFactory
别名:[SunPKIX,X509,X.509],SunJSSE:SSLContext.SSL -> com.sun.net.ssl.internal.ssl.SSLContextImpl,SunJSSE:SSLContext.SSLv3 -> com.sun.net.ssl.internal。 ssl.SSLContextImpl , SunJSSE: SSLContext.TLS -> com.sun.net.ssl.internal.ssl.SSLContextImpl , SunJSSE: SSLContext.TLSv1 -> com.sun.net.ssl.internal.ssl.SSLContextImpl , SunJSSE: SSLContext.默认 -> com.sun.net.ssl.internal.ssl.DefaultSSLContextI mpl , SunJSSE: KeyStore.PKCS12 -> com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore ] java.ext.dirs: lib com.microsoft。 sqlserver.jdbc.SQLServerException:驱动程序无法使用安全套接字层 (SSL) 加密建立与 SQL Server 的安全连接。错误:“RSA premaster secret 错误”。 ClientConnectionId:c0a357b6-e274-41b2-9fd a-7ef89ebdfb7a at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerC onnection.java:1667) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1668) )at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLSer
verConnection.java:1323) 在 com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991) 在 com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerCon nection.java:827) 在 com.microsoft .sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at TestDbConnection.main(TestDbConnection.java:13)引起:javax.net.ssl.SSLKeyException: RSA premaster secret 错误 在 com.sun.net.ssl.internal.ssl.RSAClientKeyExchange.(未知来源) 在 com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloDone(未知来源) 在 com.sun.net.ssl.internal .ssl.ClientHandshaker.processMessage(Unknown Source) at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source) at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(未知来源)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
已知来源)在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(未知来源)在 com.microsoft 的 com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(未知来源)。 sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1618)
... 7 more Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyG enerator not available at javax.crypto.KeyGenerator.<init>(DashoA13*..) at javax.crypto.KeyGenerator.getInstance(DashoA13*..) at com.sun.net.ssl.internal.ssl.JsseJce.getKeyGenerator(Unknown Source) ... 17 more
我正在提供一个外部 lib 文件夹,sqljdbc4.jar
其中包含并使用运行我的 JAR
java -Djava.ext.dirs=lib -jar TestDB.jar
我已经阅读了各种帖子,但没有工作。