Ae coi giúp mình lỗi chổ nào mà sao mình không truy cập được vào MsSQL thế. Nó báo lỗi là:
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: “PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”. ClientConnectionId:426e534d-8d13-4a73-8bab-b12d3af828d9
package Test_ConnectSQL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectSQL {
public static Connection getConnect(String strServer, String strDatabase)
{
Connection conn=null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl=
"jdbc:sqlserver://"+strServer+":1433;databaseName="+strDatabase+";integratedSecurity=true;";
conn= DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
return conn;
}
public static void main(String[] args) {
Connection connect = getConnect("ANHKHOA","SinhVien");
if (connect != null)
{
System.out.println("Successful connection");
}
else {
System.out.println("Connection failed");
}
}
}