I am trying to connect my Azure Database using JDBC. But it fails to connect. I have used server name,username,database name and password correctly.
using Mysql Connector v8.0.13
import java.sql.*;
import java.util.Properties;
public class MyConnection {
public static Connection getConnection() {
System.out.println("MySQL JDBC driver detected in library path.");
Connection connection = null;
try
{
String url ="jdbc:mysql://<servername>:3306/<databaseName>?useSSL=true&requireSSL=false";
connection = DriverManager.getConnection(url, <username>, <password>);
}
catch (SQLException e)
{
//throw new SQLException("Failed to create connection to database.", e);
}
if (connection != null)
{
System.out.println("Successfully created connection to database.");
}
else {
System.out.println("Failed to create connection to database.");
}
System.out.println("Execution finished.");
return connection;
}
}
I was expecting to show "Successfully created connection to database." but its showing "Failed to create connection to database."