public class TestConnection {
public static void main(String[] args) {
String Url = "jdbc:sqlserver://serverURL;DatabaseName=DBname;user=dbUsername;Password=dbPassword";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Trying to connect");
Connection connection = DriverManager.getConnection(Url);
System.out.println("Connection Established Successfull and the DATABASE NAME IS:"
+ connection.getMetaData().getDatabaseProductName());
} catch (Exception e) {
System.out.println("Unable to make connection with DB");
e.printStackTrace();
}
}
}
No comments:
Post a Comment