dependencies {
...
implementation 'com.microsoft.sqlserver:mssql-jdbc:9.4.0.jre11'
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionTest {
public static void main(String[] args){
Connection connection = null;
try {
String url = "jdbc:sqlserver://:;databaseName=";
String username = "";
String password = "";
connection = DriverManager.getConnection(url, username, password);
if (connection != null){
System.out.println("Connected successfully.");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try{
if(connection!= null){
connection.close();
}
} catch(SQLException e) {
e.printStackTrace();
}
}
}
}
其中,"