I am running MSSQL on docker using port 1433:
And am able to connect to it and make queries using a simple tool I downloaded from the internet (SQLDbx):
However when I try to connect using JDBC by this code:
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:1433/SocialDB/", "myUsername","myPW");
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
I get:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I wonder if there is some extra step that I have to do when running SQLServer on docker that I am missing, and if not, I wonder what could be causing the problem.
Thanks in advance.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…