I try, without any success, to connect my java project to my sql server database (local on my laptop).
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JvaConnect2SQL {
public static void main(String[] args) {
String url = "jdbc:sqlserver://LAPTOP-0CSKUFIE\\MSSQLSERVER;databaseName=datatreck";
String username = "sa";
String password = "hello";
try {
Connection connection = DriverManager.getConnection(url, username, password);
System.out.println("Connecté à SQL server");
} catch (SQLException e) {
System.out.println("Erreur - Problème lors de la connexion");
e.printStackTrace();
}
}
}
The error is :
com.microsoft.sqlserver.jdbc.SQLServerException: La connexion à l'hôte LAPTOP-0CSKUFIE, instance nommée mssqlserver, a échoué. Erreur : « java.net.SocketTimeoutException: Receive timed out ». Vérifiez le nom du serveur et celui de l'instance et veillez à ce qu'aucun pare-feu ne bloque le trafic UDP vers le port 1434. Pour SQL Server 2005 ou ultérieur, vérifiez que le service SQL Server Browser est en cours d'exécution sur l'hôte.
English Translation:
com.microsoft.sqlserver.jdbc.SQLServerException: Connection to host LAPTOP-0CSKUFIE, instance named mssqlserver, failed. Error: "java.net.SocketTimeoutException: Receive timed out". Check the server name and instance name and ensure that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser service is running. running on the host.
It seems the name of the host and/or instance are not right ><
but I was sure it was the good ones, so I'm confuse ... How can I be sure of my host/instance names ? Is the code all right ?
I add exception to the fire wall and add the jdbc driver. I don't understand why the connexion fail.