我正在尝试通过Android Studio连接我的Azure SQL数据库,以便在移动应用程序中使用。
String connectionURL = "jdbc:sqlserver://****.database.windows.net:1433;database=****;user=****@****;password=*****;encrypt=false;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30";
public void connect(){
Connection connection = null;
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(connectionURL);
}
catch (Exception e) {
e.printStackTrace();
}
这是我连接Azure数据库的代码。已导入正确的JDBC驱动程序,并且使用了正确的用户名/密码(标记为***s)。 我一直收到与SSL相关的相同错误,如下所示 -
04-03 23:04:49.449 31439-31439/com.example.melissa.dbtest W/System.err: com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Socket closed". ClientConnectionId:*****
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2435)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1816)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2022)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1687)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1528)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:866)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:569)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:569)
04-03 23:04:49.452 31439-31439/com.example.melissa.dbtest W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:237)
04-03 23:04:49.453 31439-31439/com.example.melissa.dbtest W/System.err: at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1753)
我查看了许多答案和文档,但仍然无法解决问题。如何使用SSL连接到Azure数据库?